1.

Explain The Abstract Class Modifier?

Answer»

As you have learned, Java lets you extend an existing CLASS with a subclass. Over TIME, you may start to develop your own class libraries whose classes you anticipate other programmers will extend. For some classes, there may be times when it does not make sense to implement a method until you KNOW how a programmer will extend the class. In such CASES, you can define the method as abstract, which forces a programmer who is extending the class to implement the method.

When you use the abstract keyword within a class, a program cannot create an instance of that class. As briefly discussed, abstract classes usually have abstract methods which the class did not implement. INSTEAD, a subclass extends the abstract class and the subclass must supply the abstract method's implementation. To declare a class abstract, simply include the abstract keyword within the class definition, as shown:

public abstract class Some abstract Class { }

As you have learned, Java lets you extend an existing class with a subclass. Over time, you may start to develop your own class libraries whose classes you anticipate other programmers will extend. For some classes, there may be times when it does not make sense to implement a method until you know how a programmer will extend the class. In such cases, you can define the method as abstract, which forces a programmer who is extending the class to implement the method.

When you use the abstract keyword within a class, a program cannot create an instance of that class. As briefly discussed, abstract classes usually have abstract methods which the class did not implement. Instead, a subclass extends the abstract class and the subclass must supply the abstract method's implementation. To declare a class abstract, simply include the abstract keyword within the class definition, as shown:



Discussion

No Comment Found