When a subclass that is not declared as abstract inherits an abstract class,
Similarly in object-oriented programming, you may want to model abstract concepts but you don't want to be able to create an instance of it. For example, the Number class in the java.lang package represents the abstract concept of numbers. It makes sense to model numbers in a program, but it doesn't make sense to create a generic number object. Instead, the Number class makes sense only as a superclass to classes like Integer and Float which implement specific kinds of numbers. Classes such as Number, which implement abstract concepts and should not be instantiated, are called abstract classes. An abstract class is a class that can only be subclassed--it cannot be instantiated. Show
To declare that your class is an abstract class, use the keyword If you attempt to instantiate an abstract class, the compiler will display an error similar to the following and refuse to compile your program:abstract class Number { . . . } AbstractTest.java:6: class AbstractTest is an abstract class. It can't be instantiated. new AbstractTest(); ^ 1 error An abstract class may contain abstract methods, that is, methods with no implementation. In this way, an abstract class can define a complete programming interface thereby providing its subclasses with the method declarations for all of the methods necessary to implement that programming interface. However, the abstract class can leave some or all of the implementation details of those methods up to its subclasses. |