Abstract class & method

 Abstract methods and classes

• We know that a method declare as final is not redefined in a subclass.

• We can declare abstract method with using the keyword abstract.

• We can not create the objects of abstract class directly.

• The abstract method of an abstract class must be defined in its subclass.

• We cannot declare abstract constructors or abstract static methods.

Example

Abstract class A

{

abstract void put();

void putdata()

{

System.out.println(“normal method”);

}

}

Class B extends A

{

void put()

{

System.out.println(“implementation of abstract method”);

}

}

Class impl

{

public static void main(String s[])

{

B b1=new B();

b1.put();

b1.putdata();

}

}

  • Abstract class cannot directly instantiated with new operator because abstract class cannot be fully defined.
  • Any subclass of an abstract class either implement all of the abstract method in the super class or the class method declared as abstract.
  •  You cannot declared abstract constructor or abstract static methods. 
  • The abstract methods of an abstract class must be defined in its subclass.

No comments:

Post a Comment