menu

Java Classes and Objects


1. Which of the following is not a modifier in Java?

final

static

non-static

public


2. Which keyword is used to define a class in Java?

class

object

void

new


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


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


5. Which of the following is true about local variables in Java?

They are declared inside a method or block.

They have default values.

They are initialized automatically.

They can be accessed from any method in the class.


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 keyword is used to refer to the current object in Java?

this

object

self

current


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

public

private

protected

default


9. Which keyword is used to prevent a method from being overridden in a subclass in Java?

final

static

abstract

synchronized


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

this

super

final

abstract