Appearance
question:40. If a class is not qualified as public or private, what does that imply about its public methods and fields? A. No other class can use them: class access defaults to private. B. Only classes in the same file can use them. C. Only classes in the same package can use them. D. Only classes derived from this class can use them. E. All classes can use them.
answer:C. Only classes in the same package can use them.
question:41. What’s the connection between public classes and .java file names? (Assume the file contains no inner classes.) A. The file can have at most one public class; if present, it must have the same name as the file. B. The file must have at least one public class and none of them can have the same name as the file. C. It is common practice to name a file after one of the public classes in it, but Java does not require it. D. If the file does not contain a public class, its name must not match the names of any of the classes in it. E. There is no connection!
answer:A. The file can have at most one public class; if present, it must have the same name as the file.
question:42. An interface must meet which of these restrictions? I. It must not have any fields. II. All methods must be abstract. III. Only public methods are allowed. IV. A class can implement only one interface. A. II and III only D. I, III and IV only B. I, II and III only E. I, II,III and IV C. II, III and IV only
answer:B. I, II and III only
question:Use this information when answering the next seven questions: Polygon is a class that defines regular polygons (figures such as equilateral triangles, squares, and regular pentagons—polygons where all the sides have the same length). It has, among other public methods, one named area(), which takes no parameters, and returns as type double the area of the polygon. Classes Square, EqiTriangle and Pentagon are derived from Polygon. Square and EqiTriangle each have, among other public methods, one named area(), which takes no parameters and returns as type double the area of a Square and EqiTriangle, respectively. Pentagon does not define a method named area(). 43. What fields does Square inherit from Polygon? A. Only those that have public or package access B. All except those that are private C. Only public ones D. All except those that have protected access E. All of them
answer:B. All except those that are private