Java, .NET, PHP, PYTHON, ANGULAR, .NET, ML, Data Scince, Testing, CI Tutorials in Easy Languages.

"Best Software Training, Internship, Project Development center of Indore India, Helpline 780506-3968"

Abstract class in Java:-



Abstract class is flexible as compare to interface because we can define normal method and declare abstract method both.means it is combination of Interface Features and Class Features.


We will use abstract modifier and public access specifier in abstract method


abstract class Classname
{
     data member;
     void fun()
      {

     }

   abstract access specifier returntype functionname();

}


Rules for abstract class:-

1 We can not create object of abstract class ,we should create reference of it .

2 abstract modifier should be used in Class-name and Method-name


Advantage of Abstract class:-

1)  Security :-  we can not access abstract class directly hence if we want to hide details of actual class then we can create abstract.

2) data contract :-  all abstract method must be defined by child class .


abstract class Area
{
     float a=23,b=2;  //normal  instance variable
     void triangle()
     {
        System.out.println(a*b/2);
     }

    abstract void rect();   //abstract method can be default and public
}

class Areaimple extends Area
{
    void rect()
     {
        System.out.println(a*b);
     }
}

Calling

Area obj = new AreaImple();
obj.triangle();
obj.rect();

Post a Comment

If you have any doubt in programming or join online classes then you can contact us by comment .

Previous Post Next Post