Example Inheritance
Example Inheritance
// example of inheritence
// Parent class (Super class)
class Animal {
void sound() {
System.out.println("Animals make sound");
}
}
// output
Animals make sound
Dog barks
Methode overloading
// Example of Method Overloading
class Calculator {
// output
Sum = 30
Sum = 30
Sum = 6.0
wrapper classes
// Example of Wrapper Classes in Java
public class Main {
public static void main(String[] args) {
char ch = 'X';
Character chObj = ch; // auto-boxing
// output
Integer object: 10
Primitive int: 10
Double object: 5.5
Character object: X
public ✅ ✅ ✅ ✅ ✅
protected ✅ ✅ ✅ ✅ ❌
default ✅ ✅ ✅ ❌ ❌
private ✅ ❌ ❌ ❌ ❌
Key Takeaways for Exams
✔ public → Global access.
✔ private → Only within the class (used for encapsulation).
✔ protected → Class + Subclasses + Same Package.
✔ default → Package-private (no keyword).