Objects & Classes

1.What is the default value of an object reference in Java before it is initialized?
  • A. 0
  • B. null
  • C. undefined
  • D. Garbage value

null

null

2.What happens if an object does not have any references pointing to it?
  • A. It stays in memory permanently
  • B. It is collected by the garbage collector
  • C. It is converted into a primitive data type
  • D. It throws an error

It is collected by the garbage collector

It is collected by the garbage collector

3.How does Java handle objects that are no longer referenced?
  • A. The developer must manually delete them
  • B. Java uses garbage collection to remove them
  • C. The finalize () method is always called
  • D. They remain in memory indefinitely

Java uses garbage collection to remove them

Java uses garbage collection to remove them

4.What happens if an instance variable is declared but not initialized in Java?
  • A. The compiler throws an error
  • B. It takes a random memory value
  • C. It is assigned a default value based on its type
  • D. It remains uninitialized forever

It is assigned a default value based on its type

It is assigned a default value based on its type

5.If a class has private instance variables and no getter methods, what does it imply?
  • A. The variables cannot be accessed outside the class
  • B. The variables can be accessed using reflection
  • C. The variables can be modified using super
  • D. The compiler generates implicit getter methods

The variables cannot be accessed outside the class

The variables cannot be accessed outside the class