Given:
class Book {
int id;
String name;
public Book (int id, String name) {
this.id = id;
this.name = name;
}
public boolean equals (Object obj) { //line n1
boolean output = false;
Book b = (Book) obj;
if (this.name.equals(b name))}
output = true;
}
return output;
}
}
and the code fragment:
Book b1 = new Book (101, "Java Programing");
Book b2 = new Book (102, "Java Programing");
System.out.println (b1.equals(b2)); //line n2
Which statement is true?
A. The program prints true.
B. The program prints false.
C. A compilation error occurs. To ensure successful compilation, replace line n1 with: boolean equals (Book obj) {
D. A compilation error occurs. To ensure successful compilation, replace line n2 with: System.out.println (b1.equals((Object) b2));
Given:
public class Canvas implements Drawable {
public void draw () { }
}
public abstract class Board extends Canvas { }
public class Paper extends Canvas {
protected void draw (int color) { }
}
public class Frame extends Canvas implements Drawable {
public void resize () { }
}
public interface Drawable {
public abstract void draw ();
}
Which statement is true?
A. Board does not compile.
B. Paper does not compile.
C. Frame does not compile.
D. Drawable does not compile.
E. All classes compile successfully.
Given:
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" ;
Given:
and
Which interface from the java.util.function package should you use to refactor the class Txt?
A. Consumer
B. Predicate
C. Supplier
D. Function
Assume customers.txt is accessible and contains multiple lines.
Which code fragment prints the contents of the customers.txt file?
A. Stream
B. Stream
C. Stream
D. Stream
Given that data.txt and alldata.txt are accessible, and the code fragment: What is required at line n1 to enable the code to overwrite alldata.txt with data.txt?
A. br.close();
B. bw.writeln();
C. br.flush();
D. bw.flush();
Given:
class FuelNotAvailException extends Exception { } class Vehicle { void ride() throws FuelNotAvailException { //line n1 System.out.println("Happy Journey!"); } } class SolarVehicle extends Vehicle { public void ride () throws FuelNotAvailException { //line n2 super ride (); } }
and the code fragment:
public static void main (String[] args) throws Exception { Vehicle v = new SolarVehicle ();
A. ride(); } Which modification enables the code fragment to print Happy Journey!?
B. Replace line n1 with public void ride() throws FuelNotAvailException {
C. Replace line n1 with protected void ride() throws Exception {
D. Replace line n2 with void ride() throws Exception {
E. Replace line n2 with private void ride() throws FuelNotAvailException {
Given:
public class Canvas implements Drawable {
public void draw () { }
}
public abstract class Board extends Canvas { }
public class Paper extends Canvas {
protected void draw (int color) { }
}
public class Frame extends Canvas implements Drawable {
public void resize () { }
abstract void open ();
}
public interface Drawable {
public abstract void draw ();
}
Which statement is true?
A. Board does not compile.
B. Paper does not compile.
C. Frame does not compile.
D. Drawable does not compile.
E. All classes compile successfully.
Given the code fragment:
LocalDate valentinesDay =LocalDate.of(2015, Month.FEBRUARY, 14);
LocalDate next15days = valentinesDay.plusDays (15);
LocalDate nextYear = next15days.plusYears(1); // line n1
System.out.println(nextYear);
What is the result?
A. 2016-03-01
B. A DateTimeException is thrown.
C. 2016-02-29
D. A compilation error occurs at line n1.
Given the code fragment:
public void recDelete (String dirName) throws IOException {
File [ ] listOfFiles = new File (dirName) .listFiles();
if (listOfFiles ! = null andand listOfFiles.length >0) {
for (File aFile : listOfFiles) {
if (!aFile.isDirectory ()) {
if (aFile.getName ().endsWith (".class"))
aFile.delete ();
}
}
}
}
Assume that Projects contains subdirectories that contain .class files and is passed as an argument to the
recDelete () method when it is invoked.
What is the result?
A. The method deletes all the .class files in the Projects directory and its subdirectories.
B. The method deletes the .class files of the Projects directory only.
C. The method executes and does not make any changes to the Projects directory.
D. The method throws an IOException.