Given:
< ><>>< >
Correct Answer:
:BC
When an abstract class is subclassed, the subclass usually provides implementations for all of the abstract methods in its parent class (C). However, if it does not, thenthe subclass must also be declared abstract (B).
Note: An abstract class is a class that is declared abstract—it may or may not include abstract methods. Abstract classes cannot be instantiated, but they can be subclassed.
Given:
class Cake { int model; String flavor; Cake() { model = 0;
flavor = "Unknown";
}
}
public class Test {
public static void main(String[] args) { Cake c = new Cake();
bake1(c);
System.out.println(c.model + " " + c.flavor); bake2(c);
System.out.println(c.model + " " + c.flavor);
}
public static Cake bake1(Cake c) { c.flavor = "Strawberry";
Correct Answer:
C
1200 Strawberry
1230 Chocolate
Given the code fragment:
StringBuilder sb = new StringBuilder ( ) ; Sb.append (“world”);
Which code fragment prints Hello World?
Correct Answer:
A
The java.lang.StringBuilder.insert(int offset, char c) method inserts the string representation of the char argument into this sequence.
The second argument is inserted into the contents of this sequence at the position indicated by offset. The length of this sequence increases by one.The offset argument must be greater than or equal to 0, and less than or equal to the length of this sequence.
Reference: Java.lang.StringBuilder.insert() Method
Which three are advantages of the Java exception mechanism?
Correct Answer:
ACE
A: The error handling is separated from the normal program logic.
C: You have some choice where to handle the exceptions. E: You can create your own exceptions.
Given a code fragment:<>
Correct Answer:
B