
Java Programming
May 16, 2025 at 07:42 AM
*Intermediate Java Interview Questions with Answers– Part 3*
*11. What is method overloading in Java?*
It means having multiple methods with the same name but different parameters (type or number) in the same class.
*Example:*
void print(int a) {
System.out.println(a);
}
void print(String s) {
System.out.println(s);
}
The compiler picks the method based on the arguments at compile time.
*12. What is method overriding?*
It means redefining a method from a parent class in a child class with the same signature.
*Example:*
class Animal {
void sound() {
System.out.println("Some sound");
}
}
class Dog extends Animal {
void sound() {
System.out.println("Bark");
}
}
This enables runtime polymorphism.
*13. Can we override a static method in Java?*
No. Static methods belong to the class, not the object.
If you declare a static method in both parent and child, it’s called method hiding, not overriding.
*14. What are wrapper classes in Java?*
They are used to convert primitive data types into objects.
*Example:*
int a = 10;
Integer obj = Integer.valueOf(a); // Boxing
int b = obj.intValue(); // Unboxing
Common wrapper classes: Integer, Double, Float, Character, etc.
*15. What is autoboxing and unboxing?*
- Autoboxing: Automatic conversion of primitive → wrapper
- Unboxing: Wrapper → primitive
*Example:*
Integer x = 10; // autoboxing
int y = x; // unboxing
*React ❤️ for more*
❤️
👍
♥
🦾
🍆
🇮🇱
😢
🙏
🥹
47