100% Pass
What is the default access modifier in Java?
✔✔Package-private, meaning the member is accessible only within the same package.
What is the purpose of the toString() method in Java?
✔✔It provides a string representation of an object.
What is the difference between checked and unchecked exceptions?
✔✔Checked exceptions must be handled or declared with throws, while unchecked exceptions
do not require explicit handling.
What is polymorphism in Java?
✔✔Polymorphism allows a method or object to take multiple forms, typically through method
overriding or interfaces.
How can you prevent a class from being extended?
✔✔By declaring the class as final.
1
,What is the difference between the == operator and the equals() method?
✔✔The == operator compares memory addresses, while equals() compares object values.
What is the purpose of the hashCode() method?
✔✔It returns an integer hash value for an object, used in hashing-based collections.
What is the purpose of the try-catch block?
✔✔To handle exceptions and prevent program crashes.
Can you have multiple catch blocks for a single try block?
✔✔Yes, multiple catch blocks can handle different types of exceptions.
What is the purpose of the finally block in exception handling?
✔✔It executes code after a try-catch block, whether an exception occurs or not.
How do you declare a constant in Java?
✔✔By using the final keyword with a variable.
2
, What is the purpose of the final keyword when applied to a variable?
✔✔It prevents the variable’s value from being changed after initialization.
How do you declare a method that cannot be overridden?
✔✔By using the final keyword before the method declaration.
What is the main advantage of using interfaces in Java?
✔✔They allow multiple classes to share common behavior without using inheritance.
How can you achieve multiple inheritance in Java?
✔✔By implementing multiple interfaces.
What is the difference between abstract classes and interfaces?
✔✔An abstract class can have instance variables and method implementations, while an
interface can only have constants and abstract methods (before Java 8).
What keyword is used to inherit from a class?
3