Object and Class in Java
Object is real life entities that has state, behavior and identity is known as an object.
Example : Dog
Class 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
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 :
There are 3 ways to initialize object in Java.
1) Initialization Reference variable
initialize the object through a reference variable.
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 method
We 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.
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 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