An abstract class can have static fields and static methods. You can use these static members with a class reference (for example, AbstractClass.staticMethod()) as you would with any other class. In an object-oriented drawing application, you can draw circles, rectangles, lines, Bézier curves, and many other graphic objects. These objects all share specific states (such as position, alignment, line color, fill color) and behaviors (such as move, rotate, resize, draw). Some of these states and behaviors are the same for all graphic objects (for example, position, fill color, and moveTo). Others require different implementations (such as resizing or drawing). All GraphicObjects must be able to draw or resize. They differ only in the way they do it. This is a perfect situation for an abstract superclass. You can take advantage of similarities and declare that all graphic objects inherit from the same abstract parent object (for example, GraphicObject), as shown below.

An example class in the JDK that implements multiple interfaces is HashMap, which implements the Serializable, Cloneable, and Map interfaces. If you read this list of interfaces, you can conclude that a HashMap instance can be cloned (regardless of the developer or company that implemented the class), is serializable (meaning it can be converted to byte streams; see the section Serializable objects), and has the functionality of a map. In addition, many standard methods, such as merge and forEach, have been added to the Map interface, which older classes that implemented this interface do not need to define. static and final are valid modifiers for member and method field declarations within a class. Which one should you use, abstract classes or interfaces? An abstract class is a class declared abstract, which may or may not contain abstract methods. Abstract classes cannot be instantiated, but they can be subordinate. Which of these statements are not legal statements within a class? (3), (6). Both are legal collective declarations. (1) is erroneous because a class cannot be abstract and definitive “there would be no way to use such a class”. (2) is incorrect because interfaces and classes cannot be marked as static. (4) and (5) are incorrect because classes and interfaces cannot be marked as protected.

6. When working with Ms-Dos, which command transfers a particular file from one hard drive to another? There is no abstract key in statement 3.The statement is true, but it is not an abstract class or interface. Which of the following methods declares an abstract method in a Java abstract class? Abstract classes are similar to interfaces. You cannot instantiate them, and they can contain a combination of methods declared with or without implementation. However, abstract classes allow you to declare fields that are not static and definitive, and to define public, protected, and private concrete methods. With interfaces, all fields are automatically public, static, and definitive, and all methods you declare or define (as default methods) are public. In addition, you can only extend one class, whether abstract or not, while you can implement any number of interfaces. An abstract method is a method declared without implementation (without braces and followed by a semicolon), as follows: Transient and volatile modifiers are valid only for element field declarations. First, you declare an abstract class, GraphicObject, to provide member variables and methods that are fully shared by all subclasses, such as the current position and the moveTo method. GraphicObject also declares abstract methods for methods such as draw or resize, which must be implemented by all subclasses, but must be implemented in different ways.

The GraphicObject class might resemble the following: Any non-abstract subclass of GraphicObject, such as Circle and Rectangle, must provide implementations for drawing and resizing methods: Given the following code: public class School{ public abstract double numberOfStudent(); } Which of the following statements is true? If a class contains abstract methods, the class itself must be declared abstract, as in: Which of the following class definitions defines a legal abstract class? A class declaration can only have definitive, abstract, and public modifiers, unless it is a nested class.

Comments

comments