Java programming language have utility to make a object. By creating object we can easy to access data, error handling, and the tidy code. okay no talk anymore let's make a one example.First open your IDE->Make a new project, there is have 2 class so i will describe one an one.
Student.java
public class Student {
private String _number,_name,_adress,_telpno;
public Student() {
}
public Student(String _number, String _name, String _adress, String _telpno) {
this._number = _number;
this._name = _name;
this._adress = _adress;
this._telpno = _telpno;
}
public String getAdress() {
return _adress;
}
public void setAdress(String _adress) {
this._adress = _adress;
}
public String getName() {
return _name;
}
public void setName(String _name) {
this._name = _name;
}
public String getTelpno() {
return _telpno;
}
public void setTelpno(String _telpno) {
this._telpno = _telpno;
}
public String getNumber() {
return _number;
}
public void setNumber(String _number) {
this._number = _number;
}
}
AccessClass.java
public class AccessClass {
public AccessClass() {
//make a new object Student and assign with name _student
Student _student = new Student();
// Set data from class _student
_student.setNumber("1234");
_student.setName("Hendry Apryanto");
_student.setTelpno("09090090");
_student.setAdress("California Street");
//Access data from class _student
System.out.println("Number :" + _student.getNumber());
System.out.println("Name :" + _student.getName());
System.out.println("Number Telphone :" + _student.getTelpno());
System.out.println("Address :" + _student.getAdress());
}
public static void main(String[] args) {
new AccessClass();
}
}
In student class I am desribe all property (Number,Name,Address,Number telphone) and method(Get and set for each property). Class student have a utility like a temporary data storage and we can set one on one property using method get and set. okay in AccessClass class I made object student so all property is assign to _student.At line 8-11 is using to assign data. At line 14-17 is using to get data.
okay and finnaly congurtulation you have made class and can access it. Thank you for see this tutorial...^^
Tuesday, January 25, 2011
How make class in Java
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment