The object is a memory space of a class. An object is as software bundle of variables and related methods. In other words, any entity has state and behavior is called as an object.
Example: Mobile, Bus
The java object contains only non-static methods only.By using of object we can access only non-static methods.
The object is an instance of class.
There are four ways to create an object:
1. By using new keyword
1. By using new keyword
2. By newInstance() method
Anonymous object:
An object without reference is known as an anonymous object. If one method in a class this is a good approach.
Sample program
public class Student{
int id;
public int display(int number){
id=number;
return id;
}
public static void main(String []args){
Student s = new Student(); //Creating object by using new method
System.out.println( s.display(123));
}
}
Interview Questions:
What is an object in java?
How many ways we can create an object?
What is an anonymous object?
Write a sample java program to create an object?
What do you known about java object ?
EmoticonEmoticon