0% found this document useful (0 votes)
209 views9 pages

Abstract Classes

The document discusses polymorphism, abstract classes, and the final keyword in Java. It explains that abstract classes can contain abstract and concrete methods, with abstract methods needing to be implemented in child classes. Abstract classes cannot be instantiated directly and require subclasses to override abstract methods. The final keyword prevents classes from being inherited or methods from being overridden.

Uploaded by

Visual Tech
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
209 views9 pages

Abstract Classes

The document discusses polymorphism, abstract classes, and the final keyword in Java. It explains that abstract classes can contain abstract and concrete methods, with abstract methods needing to be implemented in child classes. Abstract classes cannot be instantiated directly and require subclasses to override abstract methods. The final keyword prevents classes from being inherited or methods from being overridden.

Uploaded by

Visual Tech
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 9

Polymorphism

Polymorphism
Abstract Class
Abstract Method
Final Key word
Abstract Class

Abstract class is declared with abstract


key word.
The class contains abstract methods.
Abstract methods are declared with abstract
key word.
Abstract methods are declared inside abstract
class.
Abstract methods are defined in child class.
Abstract Class
Abstract class cannot have any object.
The child class of the abstract class must
override all the abstract methods of the
parent class.
If the child class does not override any
abstract method of the parent class it
should also be declared abstract.
Reference variable can be declared of
abstract class.
Abstract class

Abstract class may have abstract and


concrete methods.
Non abstract methods are also called
concrete methods.
All the members of the abstract class can
be accessed only through the object of the
child class.
Example #1 Abstract Class
1. Class demo
2. {
3. public static void main (String as[])
1. abstract Class A 4. {
2. { 5. B obb=new B();
3. abstract void callme(); 6. C obc=new C();
4. abstract void show(); 7. A ob;
5. } 8. Ob=obb;
6. Class B extends A 9. Ob.callme();
7. { 10. Ob.show();
8. void callme() 11. Ob=obc;
9. { 12. Ob.callme();
10. System.out.println(“call me of B”); 13. Ob.show(); } }
11. } 14. Output:
12. void show() 1. Call me of B
13. { 2. Show of B
14. System.out.println(“show of B”); 3. Call me of C
15. } } 4. Show of C
16. Class C extends A
17. {
18. Void callme()
19. {
20. System.out.println(“call me of C”); }
21. void show()
22. {
23. System.out.println(“show of C”); } }
Abstract Class
 It allows a super class to specify methods that
will be common to all its derived classes and
does not provide any definition of these
methods.
 It allows subclasses to define the specific
implementation of some or all of those methods.
 Its another way java implements one interface,
multiple methods aspect of polymorphism.
Abstract Class

By combining inheritance with overridden


methods ,a super class can define the
general form of the methods that will be
used by all of its subclasses.

This is also called run time polymorphism.


Polymorphism
The object referred by the reference
variable of the super class is determined
at run time.
The binding of object to the overrided
method is performed at run time.
The reference variable of the parent class
is binded dynamically to different methods
at run time.
Therefore its called dynamic/late binding.
Final Key word

The class declared with final key word


cannot be inherited.
The method declared with final keyword
cannot be overrided.

You might also like