Abstract classes OAn abstract class cannot be instantiated using the new operator, but you can still define its constructors which are invoked in the constructors of its subclasses O For instance the constructors of geometricObject are invoked in the circle class and the rectangle class public Circles(double radius, String color, boolean filled)i super(color, filled this. radius radius: Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 6 Abstract Classes ⚫An abstract class cannot be instantiated using the new operator, but you can still define its constructors, which are invoked in the constructors of its subclasses. ⚫ For instance, the constructors of GeometricObject are invoked in the Circle class and the Rectangle class. public Circle9(double radius, String color, boolean filled) { super(color, filled); this.radius = radius; }
Abstract classes OA class that contains abstract methods must be abstract O However, it is possible to declare an abstract class that contains no abstract methods OIn the above case, you cannot create instances ofthe class using the new operator. This class is used as a base class for defining a new subclass OA subclass can be abstract even if its superclass is concrete. For example, the object class is concrete, but its subclasses, such as Geometricobject, may be abstract Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 7 Abstract Classes ⚫A class that contains abstract methods must be abstract. ⚫ However, it is possible to declare an abstract class that contains no abstract methods. ⚫In the above case, you cannot create instances of the class using the new operator. This class is used as a base class for defining a new subclass. ⚫A subclass can be abstract even if its superclass is concrete. For example, the Object class is concrete, but its subclasses, such as GeometricObject, may be abstract
Abstract classes Cannot create an instance from an abstract class using the new operator, but an abstract class can be used as a data type. THerefore, the following statement, which creates an array whose elements are of geometricobject type, Is correct GeometricObject!l geo= new GeometricObject[10 Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 8 Abstract Classes ⚫cannot create an instance from an abstract class using the new operator, but an abstract class can be used as a data type. ⚫Therefore, the following statement, which creates an array whose elements are of GeometricObject type, is correct. GeometricObject[] geo = new GeometricObject[10];
Example 9.1 Using the GeometricObject Class o Objective This example creates two geometric objects: a circle, and a rectangle, invokes the equalArea method to check if the two objects have equal area and invokes the display GeometricObject method to display the objects genercprograng Polymorphism TestGeometricObiect dynamic binding Run Liang, introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 9 Example 9.1 Using the GeometricObject Class ⚫ Objective: This example creates two geometric objects: a circle, and a rectangle, invokes the equalArea method to check if the two objects have equal area, and invokes the displayGeometricObject method to display the objects. TestGeometricObject Run generic programming Polymorphism dynamic binding
The abstract Calendar class and Its Gregorian Calendar subclass An instance of iava. util. Date represents a specific instant in time with millisecond precision javautil. Calendar is an abstract base class for extracting detailed information such as year, month, date, hour minute and second from a date object Subclasses of calendar can implement specific calendar systems such as Gregorian calendar Lunar Calendar and Jewish calendar. Currently, java util. Gregorian Calendar for the gregorian calendar is supported in the Java API Introduction to Java Programming, revised by Dai-kaiyu
Liang,Introduction to Java Programming,revised by Dai-kaiyu 10 The Abstract Calendar Class and Its GregorianCalendar subclass ⚫An instance of java.util.Date represents a specific instant in time with millisecond precision. ⚫java.util.Calendar is an abstract base class for extracting detailed information such as year, month, date, hour, minute and second from a Date object. ⚫Subclasses of Calendar can implement specific calendar systems such as Gregorian calendar, Lunar Calendar and Jewish calendar. Currently, java.util.GregorianCalendar for the Gregorian calendar is supported in the Java API