Given:
A.
X XX
B.
X Y X
C.
Y Y X
D.
Y YY
Y YY
Given the code fragment:
public static void main (String [ ] args) throws IOException {
BufferedReader br = new BufferedReader (new InputStremReader (System.in));
System.out.print (“Enter GDP: “);
//line 1
}
Which code fragment, when inserted at line 1, enables the code to read the GDP from the
user?
A.
int GDP = Integer.parseInt (br.readline());
B.
int GDP = br.read();
C.
int GDP = br.nextInt();
D.
int GDP = Integer.parseInt (br.next());
int GDP = br.nextInt();
Given:
class UserException extends Exception { }
class AgeOutOfLimitException extends UserException { }
and the code fragment:
class App {
public void doRegister(String name, int age)
throws UserException, AgeOutOfLimitException {
if (name.length () < 6) {
throw new UserException ();
} else if (age >= 60) {
throw new AgeOutOfLimitException ();
} else {
System.out.println(“User is registered.”);
}
}
public static void main(String[ ] args) throws UserException {
App t = new App ();
t.doRegister(“Mathew”, 60);
}
}
What is the result?
A.
User is registered.
B.
An AgeOutOfLimitException is thrown.
C.
A UserException is thrown.
D.
A compilation error occurs in the main method.
User is registered.
Which statement is true about java.time.Duration?
A.
It tracks time zones.
B.
It preserves daylight saving time.
C.
It defines time-based values.
D.
It defines date-based values.
It defines time-based values.
Reference: http://tutorials.jenkov.com/java-date-time/duration.html#accessing-the-time-ofa-
duration
Given the code fragment:
public void recDelete (String dirName) throws IOException {
File [ ] listOfFiles = new File (dirName) .listFiles();
if (listOfFiles ! = null && listOfFiles.length >0) {
for (File aFile : listOfFiles) {
if (aFile.isDirectory ()) {
recDelete (aFile.getAbsolutePath ());
} else {
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.
The method deletes the .class files of the Projects directory only.
Page 5 out of 26 Pages |
Previous |