menu

Java Classes and Objects


1. Which of the following is true about instance variables in Java?

They are created when an object is created.

They are stored in the heap memory.

They are shared among all objects of a class.

They can be accessed using class name.


2. Which of the following is true about method overriding in Java?

It allows a subclass to provide its own implementation of a method in the superclass.

It allows a superclass to provide its own implementation of a method in the subclass.

It allows a method to have the same name but different signature as another method in the same class.

It allows a method to have a different name but same signature as another method in the same class.


3. Which of the following is true about interfaces in Java?

They can have instance variables.

They can be instantiated.

They can have both abstract and non-abstract methods.

They can have constructors.


4. Which of the following is not a type of constructor in Java?

Default constructor

Parameterized constructor

Private constructor

Copy constructor


5. Which method is used to compare two objects for equality in Java?

toString()

hashCode()

equals()

compareTo()


6. Which of the following is true about the super keyword in Java?

It refers to the superclass of the current class.

It refers to the subclass of the current class.

It refers to the current object.

It refers to the current class.


7. Which of the following is true about static variables in Java?

They are created when an object is created.

They are stored in the heap memory.

They are shared among all objects of a class.

They can be accessed using object reference.


8. Which of the following is not a member of a class in Java?

Variables

Methods

Constructors

Functions


9. Which of the following is true about encapsulation in Java?

It allows the state of an object to be accessed directly.

It allows the state of an object to be accessed only through methods.

It allows the state of an object to be accessed only through variables.

It allows the state of an object to be accessed through both variables and methods.


10. Which of the following is true about abstract classes in Java?

They can be instantiated.

They can contain abstract methods.

They cannot contain concrete methods.

They cannot be inherited.