ECEN324 - Computer System Software - Lecture 05
ECEN324 - Computer System Software - Lecture 05
Classes II
NU : Spring 2025,
ECEN324 -
2
Computer System
There are rules you must observe when using this:
• The this member can never be declared: it is automatically implied when you create
a Class this cannot be used in a class A to access a member of class B.
• this cannot be used in a static method
NU : Spring 2025,
ECEN324 -
3
Computer System
Working with files Example08 (object data type)
class Student implements Serializable
{
int •id;
String name;
boolean irregular;
boolean transferred;
String level;
String cc1;
String cc2;
String cc3;
String cc4;
String cc5;
String cc6;
void setStudent(int id,String name, boolean irregular, boolean
transferred, String level,
String cc1, String cc2, String cc3, String cc4, String cc5, String cc6 )
{
this.id=id;
this.name=name;
this.irregular=irregular;
4 NU : Spring 2025, ECEN324 - Computer System Software
this.transferred=transferred;
this.level=level;
oos.writeObject((Student)st1);
fout.flush();
fout.close();
}
catch (Exception ex) {
JOptionPane.showMessageDialog(this, ex);
} }
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt)
{
if (jFileChooser1.showOpenDialog(this) == 0) {
try{
oos.writeObject((Student)st1);
fout.flush();
fout.close();
}
catch (Exception ex) {
JOptionPane.showMessageDialog(this, ex);
} }
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt)
{
if (jFileChooser1.showOpenDialog(this) == 0) {
try{
NU : Spring 2024,
ECEN324 -
20
Computer System
• In your application, you can declare a class member and refer to it regardless of
which instance of an object you are using. Such a member variable is called static.
• To declare a member variable of a class as static, type the static keyword on its left.
• Whenever you have a static member, in order to refer to it, you must "qualify" it in
the class in which you want to call it.
• Qualifying a member means you must specify its class.
NU : Spring 2024,
ECEN324 -
21
Computer System
The Static Members of a Class
Static Methods
• Like a member variable, a method of a class can be defined as static.
• Consequently, this particular method can access any member of the class regardless
of the instance if there are many instances of the class declared.
NU : Spring 2024,
ECEN324 -
22
Computer System
ass Student implements Serializable
Student.setTotalStudents(Integer.parseInt(jTextField3.getText()));
}
private void jButton10ActionPerformed(java.awt.event.ActionEvent evt)
NU : Spring 2024,
ECEN324 -
24
Computer System
Thanks,..
C U next week, isA