QUESTION 101
Given the code fragment:
final String str1 ="JAVA";
StringBuffer strBuf =new StringBuffer("Course");
UnaryOperator<String> u =(str2) ->str1.concat(str2);//line2
UnaryOperator<String> c =(str3) ->str3.toLowerCase();
System.out.println(u.apply(c.apply(strBuf))); //line1
What is the result?
A. A compilation error occurs at
line n1.
B.
courseJava
C.
Javacourse
D. A compilation error occurs at
line n2.
Correct Answer:
A
Section: (none)
Explanation
Explanation/Reference:
QUESTION 102
Given:
class Engine {
double fuelLevel;
Engine(int fuelLevel){this.fuelLevel=fuelLevel;}
public void start() {
//line1
System.out.println("Started");
}
public void stop() {System.out.println("Stopped");}
}
Your design requires that:
fuelLevel
of Engine must be greater than zero when the
start()
method is invoked.
The code must terminate if
fuelLevel
of
Engine
is less than or equal to zero.
Which code fragment should be added at
line n1
to express this invariant condition?
A.
assert (fuelLevel) : “Terminating…”;
B.
assert (fuelLevel > 0) : System.out.println (“Impossible fuel”);
C.
assert fuelLevel < 0: System.exit(0);
D.
assert fuelLevel > 0: “Impossible fuel” ;
Correct Answer:
C
Section: (none)
Explanation
Explanation/Reference:
QUESTION 103