Programming Concepts Questions and
Answers 100% Pass
What happens when an exception occurs in a constructor?
✔✔ Object creation fails, and the exception must be handled.
Can an interface have static methods?
✔✔ Yes, since Java 8, interfaces can have static methods.
What is a functional interface?
✔✔ An interface with exactly one abstract method, used for lambda expressions.
Why are wrapper classes used in Java?
✔✔ To allow primitive values to be used as objects.
Can a method be both `synchronized` and `final`?
✔✔ Yes, a method can be both synchronized and final.
1
,Why is Java not 100% object-oriented?
✔✔ Because it supports primitive data types.
How do you stop object creation in Java?
✔✔ By making the constructor private.
What is constructor chaining?
✔✔ Calling one constructor from another within the same class or between parent and child
classes.
Can a `static` variable be `final`?
✔✔ Yes, a `static final` variable is a constant.
What is the difference between `deep copy` and `shallow copy`?
✔✔ A shallow copy copies references, while a deep copy creates independent copies of objects.
Can we call `super()` multiple times in a constructor?
✔✔ No, `super()` must be the first statement and can be called only once.
2
, What is a transient variable?
✔✔ A variable that is not serialized.
Can you synchronize a constructor?
✔✔ No, but you can use a synchronized block inside it.
Why is Java’s `String` class immutable?
✔✔ To improve security, caching, and performance in string handling.
What is encapsulation in Java?
✔✔ Encapsulation is the practice of wrapping data and methods into a single unit while
restricting direct access to certain details.
Can an abstract class have a constructor?
✔✔ Yes, an abstract class can have a constructor, and it is called when a subclass is instantiated.
What happens if you do not override `hashCode()` when overriding `equals()`?
3