Posts

Showing posts with the label inheritance in java

Java super Keyword (super variable, super method, super constructor)

Image
Java super Keyword: super Variable, super Method, super Constructor (With Examples) ✨ Quick Summary In this post, you’ll learn what the super keyword means in Java and why it is used. We will cover super variable , super method , and super constructor with beginner-friendly examples. Java super keyword Inheritance In our previous posts, we learned about Inheritance , Polymorphism , and the this keyword. Now, let’s learn another keyword that is used mainly in inheritance: super . 1) What is super Keyword in Java? The super keyword in Java refers to the parent class object . ✅ Simple meaning: super = parent class reference 2) Why Do We Use super Keyword? We use super keyword mainly for: ✅ To access parent class variables ✅ To call parent class methods ✅ To call parent class constructor 3) super Keyw...

Inheritance in Java (Single, Multilevel, Hierarchical)

Inheritance in Java: Single, Multilevel & Hierarchical (With Examples) ✨ Quick Summary In this post, you’ll learn what Inheritance is in Java and how one class can acquire properties and methods of another class. We will cover single inheritance , multilevel inheritance , and hierarchical inheritance with easy examples. Java OOP Inheritance OOP Concepts In our previous post, we learned about Encapsulation and how to protect data using getters and setters . Now it’s time to learn another powerful OOP concept: Inheritance . 1) What is Inheritance? Inheritance means one class (child class) can acquire the properties and methods of another class (parent class). Inheritance helps you: ✅ Reuse code ✅ Reduce duplicate code ✅ Create a clean class structure In Java, we use the keyword extends for inheritance. 2) Example of Single Inheritance Single inheritance means: one child class inherits from o...