jaorduz / OOPInheritance

This is repository with code to practice about inheritance with Java.

Repository from Github https://github.comjaorduz/OOPInheritanceRepository from Github https://github.comjaorduz/OOPInheritance

Inheritance with Java

website - jaorduz.github.io Github Github Follow @jaorduc CC License


@Javier Orduz

This repository contains a short explain and an example about Inheritance concept with a brief Java implementation.

Requirements and assumptions

  1. You should have Java installed on you computer.
  2. You should have basic level of knowledge about this programming language, but I will be happy to support.
  3. I have added some files about installation and steps to start with Java.

Inheritance

It is one of the OOP pilars through one class inherits the atributes and methods of another.

Figure source.

Implementation

To talk about inheritance in the progamming context, we will create the following files,

  1. Main.java
  2. Animal.java
  3. Bird.java
  4. Dog.java

Figure source. Figure source. Figure source.

This is a first approach about Inheritance concept with a quick implementation in Java.

Try out!

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.

References

  1. To dowload Java

  2. Source for the images fish

  3. Inheritance OpenDSA

  4. Visualization: pythontutor

About

This is repository with code to practice about inheritance with Java.

License:GNU General Public License v3.0


Languages

Language:Java 100.0%