20 October 2010
0 How to Invoke methods in a Java class?
Invoking methods in a class
The following statement creates a new "Student" object and assigns its reference to "student".
Student student = new Student();
All the public members of the object can be accessed with the help of the reference.
Student student = new Student();
student.setRollNo(20);
System.out.println(student.getRollNo());
The reference can be treated as the name of an object.student.setRollNo(20);
System.out.println(student.getRollNo());
For using a Student object, a programmer need not know the internal implementation details of the class. One needs to know only the public methods to use a Student object. Abstraction is achieved by hiding the irrelevant implementation details and exposing the relevant interface details.
Subscribe to:
Post Comments (Atom)
0 comments:
Please give your valuable comments.