menu

Java Classes and Objects

Java Classes and Objects - Important Points


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

A. They are created when an object is created.

B. They are stored in the heap memory.

C. They are shared among all objects of a class.

D. They can be accessed using object reference.

Discuss Work Space

Answer: option c

Explanation:

Static variables are shared among all objects of a class. They are stored in the class memory and can be accessed using the class name.

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

A. They are created when an object is created.

B. They are stored in the heap memory.

C. They are shared among all objects of a class.

D. They can be accessed using class name.

Discuss Work Space

Answer: option a

Explanation:

Instance variables are created when an object is createThey are stored in the heap memory and can be accessed using object reference.

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

A. They are declared inside a method or block.

B. They have default values.

C. They are initialized automatically.

D. They can be accessed from any method in the class.

Discuss Work Space

Answer: option a

Explanation:

Local variables are declared inside a method or block. They do not have default values and need to be initialized before use. They cannot be accessed from outside the method or block.

29. Which of the following is true about method overloading in Java?

A. It allows a method to have the same name and signature as another method in the same class.

B. It allows a method to have the same name and signature as a method in a different class.

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

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

Discuss Work Space

Answer: option c

Explanation:

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

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

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

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

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

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

Discuss Work Space

Answer: option a

Explanation:

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


Subscribe for Latest Career Trends
Subscribe Now
Use AI and ChatGPT for Career Guidance

Unlock Your Future

Join Now
Worried for Placements in 2024?

Join FAST TRACK Course

Join Now
Supercharge Your SUCCESS

Join All in One Placement Mock Tests-2024

Join Now