Wednesday 28 August 2013

Abstract Classes

Abstract classes are those classes which contain abstract method.
unimplemented methods are known as abstract method.
we can say that method without body.
if any method is not defined then it must be declared by abstract keyword.
if one method is abstract then class should be declared as abstract
we cannot create object to abstract class.
Any class can be declared as abstract no matter it is containing abstract method or not.
if a class doesn't contain any abstract method,you will declare it abstract without any error.
by using abstract class you are restricting another  class for creating the object.

Example:-

we cannot declared defined method as abstract..

Example:-


inside class B test method is getting implemented

Example 2:-


contains 2 abstract methods which is getting implemented in class B

we can also create constructor in abstract class
like this:-


in the constructor of B class which contains the by default statement super();
which calls the constructor of super class.
by this we can create constructor in abstract class.



No comments :

Post a Comment