Interviews2 answers
What is an Object in Java? How Do we create an Object in Java?
2 Answers
We can’t instantiate an interface in java . We can create object of the implemented class .But the instance of Interface
interface Pet{
public void test();
}
class Dog implements Pet{
public void test(){
System.out.println("Interface Method Implemented");
}
public static void main(String args[]){
Pet p = new Dog();
p.test();
}
}
Laxmidhar SahooPosted Jan 8, 2020, 4:24 AM EST
An object is a basic concept of oops like java classes .objects like an entity, which has a state and behavior.
Objects represent identity, which uniquely identifies it. Like one car number plate is a different number of other cars. so, it is the car’s identity which is unique.
In Java new keyword is used to create an object.
Syntax:
<class-name> [object-name] = new <class-default-constructor>
For a detailed tutorial about Objects in Java, visit
https://www.c-sharpcorner.com/article/a-complete-java-classes-tutorial/
Vijay KumariPosted Sep 16, 2019, 1:23 AM EDT


