• Breaking News

    Sunday 27 April 2014

    What is class and object.

    Object is real world entity. we can say student,vehicle etc are object. and each object have some attribute which describe that object for student attribute are name of student,marks etc.

    class is basically a template by using that template we create more than one object of same properties.

    but question arise how we create object using java language.

    for example we have a class Student and properties of that class is name and marks.

    class Student{

            String name;
            int marks;

    }

    if we want to create object of above class then we use following syntax

    Student student=new Student(); 


    when this code is executed then default constructor of Student class is executed and which initialized name and marks to their default value. and return reference of object which is store in student variable of class Student. Now we access the properties of Student class object  using student variable which contain reference of student object.


    Note: Here student is not a object but it contain reference of created object.

    if we done following thing.

    Student student;

    then  student contain null which not point to any object.






    No comments:

    Post a Comment