Java_Exam_Topics_Answers
Java_Exam_Topics_Answers
1. Method Overloading
Method overloading is a feature in Java where multiple methods can have the same name but different
Example:
class Example {
void display(int a) {
void display(String a) {
Purpose: Improves readability and allows the same method name to be used for different data types.
2. Garbage Collection
Garbage Collection in Java is the process of automatically removing unused objects from memory to free up
resources.
finalize(): Method called by garbage collector before destroying an object (rarely used in modern Java).
finally: A block that always executes after try-catch, used for cleanup operations.
Example:
try {
// risky code
} catch(Exception e) {
// exception handling
} finally {
// always executed
|------------------|-------------------------|-------------------------|
5. Inheritance
Inheritance allows one class (child) to inherit the properties and methods of another class (parent).
Example:
class Animal {
void sound() {
System.out.println("Animal sound");
void bark() {
System.out.println("Bark");
6. Interface
An interface in Java is a reference type, similar to a class, that can contain only abstract methods (Java 8+
Example:
interface Animal {
void sound();
}
Java Exam Topics - Well Explained Answers
System.out.println("Bark");
|----------------------|------------------------|--------------------------|