40 likes | 186 Views
ABSTRACT CLASSES. IHTESHAM UL HAQ. ABSTRACT CLASSES. Abstract classes are kinds of classes which cannot be instantiated. Means we cannot create an object of the class. But what we can do is to create certain variables and methods which might not be empty.
E N D
ABSTRACT CLASSES IHTESHAM UL HAQ
ABSTRACT CLASSES • Abstract classes are kinds of classes which cannot be instantiated. • Means we cannot create an object of the class. • But what we can do is to create certain variables and methods which might not be empty. • Abstract classes can then be inherited or extended in the same way as other classes can be inherited. • Abstract classes can be used as a main parent for some kind of a group of objects. • Abstract classes provide a default method for us means if we want to use some pre-defined method for us, it can be used. • We can then create an object of its child class.
ABSTRACT CLASSES • Declaring an Abstract Class //Parent.java public abstract class Parent{ public int x= 19; public void welcome(){ ………………………………….. } public int result(){ …………………………….. } public String hello(){ ……………………………….. } } //AChild.java public class AChild extends Parent{ ……………….. } child //Runit.java public class Runit{ Parent p = new Paerent(); } If we now create an object of the abstract Class it wont , it will give an error. //Runit.java public class Runit{ AChild ac = new AChild(); } Now this will work