ABSTRACT CLASSES:
There are 2 types of classes – Abstract class and concrete class
When abstract is written before class then it is abstract and rest of classes
(where nothing is written) is concrete class
We can create objects of concrete class but we cannot create object of
abstract class
We can write reference variable for both concrete and abstract class
Like abstract class there are abstract methods also =>Methods with no
body,They do not have flower brackets {} they are having only semi-colon
=>They are undefined method
If a class contains a abstract method then it becomes abstract class, if a
class has something not defined then it becomes abstract class
If a class is not completely defined then its object cannot be created
Abstract classes contains one or more number of abstract methods
If any class inherits from abstract class then it also becomes abstract class
to it to becomes concrete class it need to over-ride all the abstract
methods of the abstract super class
Here Sub extends from Super so it also becomes abstract class
Here in this class Sub class must also be abstract class
but here the meth2 which was abstract method in the
Super class is over-ridden in Sub class and it becomes
a defined method and hence the Super class becomes
a concrete class
From this clearly we
can see that when we
give the keyword
abstract to the class
super we are not able
to create an object for
the class super
Here there is an abstract method inside the class super so the class super
should also be declared as abstract and here
We can create reference for that abstract class
Super s;
But we cannot create an object for that object
Such abstract classes are meant only for inheritance and the inherited
class must over-ride the abstract method
Else that inherited class also must also be declared as a abstract class
Here an another sub class is been initialised and it inherits from the super
class and the abstract method is been over-ridden and the now the sub
class becomes a concrete class
And here now we can create object also
Super s=new Sub();
Sub class object with super class reference
Here we can call the methods from super class and also super class using
this object
s.meth1() and also s.meth2() is possible..
RULES OF ABSTRACT CLASSES:
(1)Abstract classes can never be final class-final classes are those which
cannot be extended while the abstract class can be made as concrete
class by extending them and over-riding them.
(2)Also static class can never be abstract class