✔ JAVA CHAPTERS:-
1. Introduction to Java
2. Features of Java
3. Java Virtual Machine
4. D/F B/W JVM, JRE, JDK
5. Java Data Types
6. Java Programs
7. Setting Java Path
8. OOPs Concepts
9. Object & Class In Java
10. OOPs Continued
11. Encapsulation & Polymorphism
12. Method Overloading
13. Method Overriding
14. Dynamic Method Dispatch
15. Association In Java
16. Inheritance in Java
17. Aggregation in java
18. Command Line Argument
19. Execute Command Line
20. Read Input From Command Line
21. Abstract Class In Java
22. Interface in Java
23. Cutom Marker Interface
24. Constructor In Java
25. Package in Java
26. Acess Modifier In Java
27. Static Import In Java
28. Package Class In Java
29. This Keyword
30. Instance Intializer Block
31. Super Keyword
32. Static Keyword
33. Final Keyword
1. Introduction to Java
2. Features of Java
3. Java Virtual Machine
4. D/F B/W JVM, JRE, JDK
5. Java Data Types
6. Java Programs
7. Setting Java Path
8. OOPs Concepts
9. Object & Class In Java
10. OOPs Continued
11. Encapsulation & Polymorphism
12. Method Overloading
13. Method Overriding
14. Dynamic Method Dispatch
15. Association In Java
16. Inheritance in Java
17. Aggregation in java
18. Command Line Argument
19. Execute Command Line
20. Read Input From Command Line
21. Abstract Class In Java
22. Interface in Java
23. Cutom Marker Interface
24. Constructor In Java
25. Package in Java
26. Acess Modifier In Java
27. Static Import In Java
28. Package Class In Java
29. This Keyword
30. Instance Intializer Block
31. Super Keyword
32. Static Keyword
33. Final Keyword
Read Input from Command Line: Previous Next: Interface In Java
Abstract Class In Java
Abstract class in real world:
Let us take an example of graphic objects. Different graphic objects are there such as circle, rectangle, triangle etc. They all have state defined by their positions, color etc. and behavior defined by draw, re size, calculate size etc. As all these object types has common things but with different implementations. We can take advantage of common things with different implementations and put these common things in an abstract class (say Graphic Objects) then extends this class in sub classes to provide specific implementations.
Abstract class in java:
Abstract class is a way of implementing 0 to 100% abstraction. A class declared with abstract keyword is known as an abstract class. An abstract class may or may not contain abstract method. Abstract classes cannot be instantiated.
Syntax:
abstract class className {
// declare fields
// declare abstract/non-abstract methods
}
|
Abstract method:
A method with no implementation i.e. without braces and followed by a semicolon.
Syntax:
abstract return_type methodName(); |
Example:
Output:
If a class have one abstract method it must be an abstract class but vice versa is not true i.e. it is not necessary that an abstract class have an abstract method.
Example:
If a class extends abstract class than either it has to provide implementation of all abstract methods or declare this class as abstract class.
Example:
Output:
An abstract class can have both static and non-static data members and methods like any other java class.
Example:
Output:
Why abstract class is used:
Abstract class in java is used to implement 0 to 100% abstraction.
Note: Abstract class provide 0 to 100% abstraction because it may contain no abstract method or it may contain some of its methods as abstract methods or it may contain all its methods as abstract methods.
Can abstract class have constructors in Java?
Yes, abstract class have constructors in java. But it is not used to instantiate abstract class. It is used in constructor chaining or to initialize abstract class common variables.
Can abstract class be final in Java?
No, abstract class can’t be final in Java because abstract classes are used only by extending and if they made final they can’t extended.