Archive for November, 2006

[ Team LiB ] Review Questions 6.12 Which

Monday, November 20th, 2006

[ Team LiB ] Review Questions 6.12 Which statements are true about interfaces? Select the two correct answers. a. Interfaces allow multiple implementation inheritance. b. Interfaces can be extended by any number of other interfaces. c. Interfaces can extend any number of other interfaces. d. Members of an interface are never static. e. Members of an interface can always be declared static. 6.13 Which of these field declarations are legal within the body of an interface? Select the three correct answers. a. public static int answer = 42; b. int answer; c. final static int answer = 42; d. public int answer = 42; e. private final static int answer = 42; 6.14 Which statements are true about interfaces? Select the two correct answers. a. The keyword extends is used to specify that an interface inherits from another interface. b. The keyword extends is used to specify that a class inherits from an interface. c. The keyword implements is used to specify that an interface inherits from another interface. d. The keyword implements is used to specify that a class inherits from an interface. e. The keyword implements is used to specify that a class inherits from another class. Page 322

Note: If you are looking for good and affordable webspace to host and run your servlet application check Virtualwebstudio servlet hosting services

Page 319

Monday, November 20th, 2006

Page 320
Note: If you are looking for reliable and quality webspace company to host and run your servlet application check Actions servlet hosting services

Page 319

Monday, November 20th, 2006

[ Team LiB ] Page 321
Note: If you are looking for reliable and quality webspace company to host and run your servlet application check Actions servlet hosting services

Page 319

Monday, November 20th, 2006

Page 319
Note: If you are looking for reliable and quality webspace company to host and run your servlet application check Actions servlet hosting services

[ Team LiB ] Page 316

Monday, November 20th, 2006

Page 318
Note: If you are looking for cheap and inexpensive provider to host and run your tomcat application check Actions tomcat hosting services

[ Team LiB ] Page 316

Monday, November 20th, 2006

[ Team LiB ] 6.4 Interfaces Extending classes using single implementation inheritance creates new class types. A superclass reference can denote objects of its own type and its subclasses strictly according to the inheritance hierarchy. Because this relationship is linear, it rules out multiple implementation inheritance, that is, a subclass inheriting from more than one superclass. Instead Java provides interfaces, which not only allow new named reference types to be introduced, but also permit multiple interface inheritance. Defining Interfaces A top-level interface has the following general syntax: interface // Interface header { // Interface body } In the interface header, the name of the interface is preceded by the keyword interface. In addition, the interface header can specify the following information: . scope or accessibility modifier (see Section 4.7, p. 131) . any interfaces it extends (see Section 6.4, p. 254) The interface body can contain member declarations which comprise . constant declarations (see Section 6.4, p. 255) . method prototype declarations (see Section 6.4, p. 254) . nested class and interface declarations (see Section 7.1, p. 284) An interface does not provide any implementation and is, therefore, abstract by definition. This means that it cannot be instantiated, but classes can implement it by providing implementations for its method prototypes. Declaring an interface abstract is superfluous and seldom done. The member declarations can appear in any order in the interface body. Since interfaces are meant to be implemented by classes, interface members implicitly have public accessibility and the public modifier is omitted. Interfaces with empty bodies are often used as markers to tag classes as having a certain property or behavior. Such interfaces are also called ability interfaces. Java APIs provide several examples of such marker interfaces: java.lang.Cloneable, java.io.Serializable, java.util.EventListener. Method Prototype Declarations An interface defines a contract by specifying a set of method prototypes, but no implementation. The methods in an interface are all implicitly abstract and public by virtue Page 317
Note: If you are looking for cheap and inexpensive provider to host and run your tomcat application check Actions tomcat hosting services

[ Team LiB ] Page 316

Monday, November 20th, 2006

[ Team LiB ] Page 316
Note: If you are looking for cheap and inexpensive provider to host and run your tomcat application check Actions tomcat hosting services

Page 313

Monday, November 20th, 2006

[ Team LiB ] Page 314

Hint: This post is supported by Gama web hosting hrvatska services

Page 313

Monday, November 20th, 2006

[ Team LiB ] Review Questions 6.9 Given the following code, which of these constructors can be added to MySubclass without causing a compile-time error? class MySuper { int number; MySuper(int i) { number = i; } } class MySub extends MySuper { int count; MySub(int cnt, int num) { super(num); count=cnt; } // INSERT ADDITIONAL CONSTRUCTOR HERE} Select the one correct answer. a. b. c. d. e. f. MySub() {} MySub(int cnt) { count = cnt; } MySub(int cnt) { super(); count = cnt; } MySub(int cnt) { count = cnt; super(cnt); } MySub(int cnt) { this(cnt, cnt); } MySub(int cnt) { super(cnt); this(cnt, 0); } 6.10 Which statement is true? Select the one correct answer. a. A super() or this() call must always be provided explicitly as the first statement in the body of a constructor. b. c. If both a subclass and its superclass do not have any declared constructors, the implicit default constructor of the subclass will call super() when run. If neither super() nor this() is declared as the first statement in the body of a constructor, then this() will implicitly be inserted as the first statement. d. If super() is the first statement in the body of a constructor, then this() can be declared as the second statement. Page 315

Hint: This post is supported by Gama web hosting hrvatska services

Page 313

Monday, November 20th, 2006

Page 313

Hint: This post is supported by Gama web hosting hrvatska services