In java every class follows a specific structure.Which is as follow........
<access specifies> class <class name> {
//fields and variables declarations.
//constructors.
//get and set properties
// methods
// main method (optional)
}
if class is a gui class then some other blocks will included. which are explained in older blogs.
for example ---
public class MyApp {
int id;
double salary;
String name;
public MyApp() {
id=0;
salary=0d;
name="";
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String info() {
return "Name :"+this.name+"\nId: "+this.id+"\nSalary :"+this.salary;
}
}
No comments:
Post a Comment