Sunday, 18 September 2016

object of class

Object 


Object of oops principal

Definition 1
  • Instance of a class is known as an object
  • Instance is a way of allocating the sufficient amount of memory for data members.
Definition 2
  • Group of items exists in single entity is known as an object.
  • We can say single entity means an object variable which holds group of values.
Definition 3
  • Real world entities are called as objects.
Definition 4
  • Logical runtime entities are called as objects.
Note
  • An object can exists physically in this world but class does not exist.
  • An object does not exist without class but class can exist withutout object
  • Cooooool got confusedd..?
  • Simply i can say object will come from class.
Syntax 
         Classname objectname = new constructor();
Example:
         Student s1 = new Student();
  • Classname(Student) represents the name of the class
  • objectname(s1) represents any java valid variable name.
  • by using new(new) operator we will create an object for class.
  • If constructor(Student()) will exists in class(Student) then at the time of object creation it will be called automatically
Note
  • We will learn clearly about constructor in upcoming chapter.
Why should we create an object?
  • Once if you define any variable or data in java program then immediately memory will be not allocated for that data.
  • If we create an object for that class then memory will be assign to the data.
Thanks for your time.
Nireekshan