DEV Community

Cover image for oops
a gorde
a gorde

Posted on

oops

No this is OOPS concepts;

1) Abstraction
abstraction hiding implementations details and only showing functionality.

interface one{
     void start();
     // Focus on “what” not “how”
}
Enter fullscreen mode Exit fullscreen mode

2) Encapsulation
a wrapper which creates the object of the class with private variables but public getters/setters.

class Student {
    private int age;

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}
Enter fullscreen mode Exit fullscreen mode

3) Polymorphism
Two Types

  1. 1 compile time (it overloads the methods)
int add(int a, int b)
double add(double a, double b)
Enter fullscreen mode Exit fullscreen mode
  1. 2 runtime (it overriders the method)
class Animal {
    void sound() {
        System.out.println("Barking")}
}

class Dog extends Animal {
    void sound() {
        System.out.println("Bark");
    }
}
Enter fullscreen mode Exit fullscreen mode

4) Inheritance
easy its just in the word it inherit...Hierarchy

class Animal {
    void eat() {}
}

class Dog extends Animal {
    void bark() {}
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)