Inheritance — Java (6/100)

public class Animal{public void eat(){
//Your implementation here
}
public void sleep(){
//Your implementation here
}
}
public class Elephant{int weight;
int age;
public int getAge(){}
public int getWeight(){}
public void printName(){}
public void eat(){}
public void sleep(){}
}
public class Elephant extends Animal{//By extending this class inherits all the properties and behaviors      //which in this case include the eat() and sleep() methodsint weight;
int age;
public int getAge(){}
public int getWeight(){}
public void printName(){}
//Inherits the eat() method
//Inherits the sleep() method
}
  • Child class
  • Sub-class
  • Derived class
  • Parent class
  • Super class
  • base class

Multi-Level Inheritance

Class A {}Class B extends A {} Level 1Class C extends B() Level 2

Single Level Inheritance

Class A {}Class B extends A {}

Hierarchical Inheritance

Class A {}Class B extends A {} Child 1Class C extends A {} Child 2Class D extends A {} Child 3

--

--

--

Business oriented technology enthusiast, sharing ideas from the idea valley inside my immensely curious mind, A boring Software developer and a Gaming Nerd

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Linux Cheatsheet, Linux commands helpful for everyone

Android — Implement Dark mode in a quick way

Deploy Simple Web App Using Jenkins

A Spectrum of Opportunities for Builders: Chainwhiz teams up with Web3Bridge

Kotlin — Increasing Readability (Scope Functions)

Embrace the chaos … engineering

How To Ace On-Campus Placement.

Why Your Tech Stack Matters

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Rana M. Suleman

Rana M. Suleman

Business oriented technology enthusiast, sharing ideas from the idea valley inside my immensely curious mind, A boring Software developer and a Gaming Nerd

More from Medium

Singleton Design Pattern (Java)

Collections in Java

Java record: A Brief

Assertions In Java