Skip to content

Latest commit

 

History

History
38 lines (33 loc) · 800 Bytes

File metadata and controls

38 lines (33 loc) · 800 Bytes

Inharitance

Classes can reuse code and properties from other classes. Relationships and subclasses between objects can be assigned, enabling developers to reuse common logic, while still maintaining a unique hierarchy. Inheritance forces more thorough data analysis, reduces development time and ensures a higher level of accuracy.

Example in Java:

Shape.java file

class Shape {
    String name;
    Shape() {
        this.name = "Shape";
    }
    void draw() {
        System.out.printf("draw %s", name);
    }
}

Circle.java file

class Circle extends Shape {
    public Circle() {
        name = "Circle";
    }
}

Usage:

Main.java file

class Main {
    public static void main(String[] args) {
        Shape shape = new Circle();
        shape.draw();
    }
}