Data Abstraction
Data Abstraction
In Java, the following some important observations about abstract classes are as
follows:
1.In Java, just like in C++ an instance of an abstract class cannot be created, we
can have references to abstract class type though. It is as shown below via the
clean Java program.
2. Like C++, an abstract class can contain constructors in Java. And a constructor
of an abstract class is called when an instance of an inherited class is created.
It is as shown in the program below as follows:
3. In Java, we can have an abstract class without any abstract method. This allows
us to create classes that cannot be instantiated but can only be inherited. It is
as shown below as follows with help of a clean java program.
4. Abstract classes can also have final methods (methods that cannot be overridden.
5. For any abstract java class we are not allowed to create an object i.e., for an
abstract class instantiation is not possible.
6. Similar to the interface we can define static methods in an abstract class that
can be called independently without an object.
7. We can use the abstract keyword for declaring top-level classes (Outer class) as
well as inner classes as abstract
8. If a class contains at least one abstract method then compulsory that we should
declare the class as abstract otherwise we will get a compile-time error