20 October 2010

0 How to Create Objects in Java?

Creating Objects in Java

In Java, all objects are created dynamically. The operator "new" is used for dynamic memory allocation.

The following statement creates an object of the class Student
new Student()
The above statement returns a reference to the newly created object. Creation of objects and arrays are very similar in Java.
The following statement creates a reference to the class "Student".
Student student;
The reference "student" can be used for referring to any object of type "Student".
//Declare a reference to class "Student"
Student student;
//Create a new Student object
//Make student refer to the new object
Student student = new Student();


0 comments:

Feeds Comments

Please give your valuable comments.