Inheritance with Java
This repository contains a short explain and an example about Inheritance concept with a brief Java implementation.
- You should have Java installed on you computer.
- You should have basic level of knowledge about this programming language, but I will be happy to support.
- I have added some files about installation and steps to start with Java.
It is one of the OOP pilars through one class inherits the atributes and methods of another.
To talk about inheritance in the progamming context, we will create the following files,
- Main.java
- Animal.java
- Bird.java
- Dog.java
This is a first approach about Inheritance concept with a quick implementation in Java.
Go to this website: Ref. [4] and introduce this code:
class Animal {
void fly(){
System.out.println("This animal flies");
}
void high(){
System.out.println("This animal lives up high");
}
}
public class Bird extends Animal{
int wings = 2;
public void chirp(){
System.out.println("is chirping");
}
public static void main(String[] args){
System.out.println("Hi Inheritance!");
Bird bird = new Bird();
bird.fly();
bird.chirp();
}
}
Check the simulation, then add one atribute, and one subclass.
-
To dowload Java
-
Source for the images fish
-
Inheritance OpenDSA
-
Visualization: pythontutor