Modal Box

Java Abstract class

In java abstract class is a partial implementation of abstraction while interface is implementation of full abstraction. Abstract class is declared with keyword abstract before 

 

Abstract class may have both abstract as well as non abstract methods. 

  1. Abstract class may not be intialized 
  2. Abstract class is used after inheriting it
  3. in sub class all abstract methods of abstract class has to be override.
  4. Abstract method also defined with abstract keyword and function overloading may also be done in abstract class.

Abstract class example.

  abstract class worker
     {
      void nonAbsMethod(String msg)
       {
	
        System.out.println("Msg in non asbtract method"+msg);
       }

      abstract void getPayment(int a);
 
      abstract void getPayment();
}
class employee extends worker
{ void subClassMethod() { System.out.println("sub class method "); } void getPayment(int a)

{ System.out.println("Payment Given "+a); }
   void getPayment()
{ System.out.println("Default Payment 10000"); } } class checkMain
{
public static void main(String args[])
{
// wroker w1= new worker(); we can not create the object of abstract class.
employee e1= new employee();
e1.nonAbsMethod("Hi Hello");
e1.subClassMethod();
e1.getPayment(15000);
e1.getPayment();
}
}

Output of the above program is as following.

Video/ C Introduction

Watch video in full size