menu

Java Classes and Objects


1. Which of the following is a constructor in Java?

public void MyClass()

public MyClass()

public int MyClass()

public MyClass(int x)


2. Which of the following is not a type of access modifier in Java?

public

private

protected

package


3. 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.


4. Which keyword is used to refer to the current object in Java?

this

object

self

current


5. Which keyword is used to declare a variable constant in Java?

final

static

abstract

volatile


6. 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.


7. 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.


8. Which keyword is used to implement inheritance in Java?

extends

implements

super

this


9. Which of the following is not an access specifier in Java?

public

private

protected

default


10. 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.