Abstraction meaning explained in simple terms with example : Java

 ABSTRACTION

* Show functionality hide complexity

*Abstraction implements through abstract class and interface

*If  any class has any abstract method then it can not be instantiated

*Abstract method can not be used in normal class ,but used in abstract class

*Abstract class may have abstract functions.

*Any child class has to override all the abstract class's abstract function othrwise child has to  
  become abstract.

*We never call the abstract function explicitly.automatically runs the code of the abstract
     function.

* It is not mandatory that abstract class should have atleast one abstract function

* Cant mark class as abstract and final both ....both have opposite meaning





Example :


abstract class Base
{
    int x,y;
    void show()
    {
        System.out.println("x");
        System.out.println("y");
    }
    abstract void  display();
}

class child extends Base
{
    void set (int x,int y)
    {
        this.x=x;
        this.y=y;
        System.out.println("x "+x);
        System.out.println("y "+y);
        
    }
    void display()
    {
        System.out.println("revoke");
        
    }
    public static void main(String args[])
    {
        child c1= new child();
        c1.set(10,20);
        c1.show();
        c1.display();
    }
}

About The Author

Subham Mittal has worked in Oracle for 3 years.
Enjoyed this post? Never miss out on future posts by subscribing JavaHungry