Contact Us || Privacy Policy || About Us |
|
Object and Class in Java1) ObjectObject is real life entities that has state, behavior and identity is known as an object.
Example : Dog ![]() 2) ClassClass is blue print of an object that means It represents the set of properties or methods. class can contain that is:
Syntax of class declare :What is Method in Java .?Method is like a function which is used to pass data, as a parameters, into a method, expose the behavior of an object. Advantage of Method
Example :Output ![]() new keyword in Java→ Objects are created by the help of "new" keyword. new keyword is used to allocate memory at runtime → new keyword is used to create a new object of a class. Example : Create a new instance of a class:Full Example1 :Output ![]() Example2 :Output ![]() Initialize objectThere are 3 ways to initialize object in Java.
1) Initialization Reference variableinitialize the object through a reference variable. Example1 :Output : (1)save by the class Student.java name and run TestEx see in fig.. ![]() Output : (2) Direct save by the class TestEx.java name and run TestEx see in fig.. ![]() 2) Initialization through methodWe are creating the objects of Student class and initializing the value to these objects by invoking the insertRecord method. Here, we are displaying the data of the objects by invoking the display() method. Example1 :Output ![]() 3) Initialization through a constructorNext Topic discuss, More Details....Create an object in Java?There are three ways to create an object in java. That is....
Anonymous objectAnonymous means nameless. An object which has no reference is known as an anonymous object. It can be used at the time of object creation only. If you have to use an object only once, an anonymous object you can use : Calling method through a reference: Calling method through an anonymous object Example Output: ![]()
Next TopicConstructor
|