secretofreading(Stay Tuned To My Blog For More Updates!!!)(Blog is for sale any one want to buy just fill out the contact form...

Saturday, 8 June 2013

Abstract Classes


 




 Abstract Classes
----------------
concrete method:-
----------------
It is a method with body.When all the objects want to perform same task.We should write a concrete method in the class.

Abstract method:-
----------------
A method with out body is called abstract method.When the same method should be implemented differently for different objects.Then we should write it as an abstract method.

Abstract class:-
---------------
A class that contains abstract methods is called abstract class.
Both the abstract class and abstract methods should be declared using the keyword 'abstract'.

Note:- We cannot create object for Abstract class.

diagram:-

ex:- w.a.p in which abstract class Car contains an instance        variable,one concrete method and two abstract methods.And write      two sub classes to implement Car abstract class.And write a      program to use all features of abstract class by creating a      reference to it.
                                             
imp points:-
-----------
1.An abstract class is a class with 0 (or) more abstract methods.
2.An abstract class may have instance variables and concreate methods     in addition to abstract methods.
3.We can not create an object to an abstract class.
4.We can create a reference of abstract class.
5.All the abstract methods of abstract class should be implemented in    its sub classes.
6.If any abstract method is not implemented,then the sub class should      also be declared as 'abstract'.
7.Abstract class reference can be used to refer to all objects of its      sub classes.
8.A class can not be declared as both 'abstract' and 'final'.
ex:- final abstract class A  // invalid
                                       


H.W:-
create abstract class 'Parent' with property details and an    abstract method 'calculate()'.Now derive 'Son' class from 'Parent'    class and calculate the son's property by implementing    'calculate()' method.



No comments:

Post a Comment