Given:
What is the result?
A.
The program prints nothing
B.
A NullPointerException is thrown at runtime.
C.
A StringIndexOutOfBoundsException is thrown at runtime.
D.
AnArrayIndexOutOfBoundsException is thrown at runtime
A StringIndexOutOfBoundsException is thrown at runtime.
Given:
public class Foo<K, V> {
private K key;
private V value;
public Foo (K key, V value) (this.key = key; this value = value;)
public static <T> Foo<T, T> twice (T value) (return new Foo<T, T> (value, value); )
public K getKey () (return key;)
public V getValue () (return value;)
}
Which option fails?
A.
Foo<String, Integer> mark = new Foo<String, Integer> (“Steve”, 100);
B.
Foo<String, String> pair = Foo.<String>twice (“Hello World!”);
C.
Foo<?, ?> percentage = new Foo <> (97, 32);
D.
Foo<String, String> grade = new Foo <> (“John”, “A”);
Foo<?, ?> percentage = new Foo <> (97, 32);
Given the code fragments:
What is the result?
A.
Super
Sub
Sub
B.
Contract
Contract
Super
C.
Compilation fails at line n1
D.
Compilation fails at line n2
Compilation fails at line n2
Given the content of /resourses/Message.properties:
welcome1=”Good day!”
and given the code fragment:
Properties prop = new Properties ();
FileInputStream fis = new FileInputStream (“/resources/Message.properties”);
prop.load(fis);
System.out.println(prop.getProperty(“welcome1”));
System.out.println(prop.getProperty(“welcome2”, “Test”));//line n1
System.out.println(prop.getProperty(“welcome3”));
What is the result?
A.
Good day!
Test
followed by an Exception stack trace
B.
Good day!
followed by an Exception stack trace
C.
Good day!
Test
null
D.
A compilation error occurs at line n1.
A compilation error occurs at line n1.
Given:
Class A { }
Class B { }
Interface X { }
Interface Y { }
Which two definitions of class C are valid?
A.
Class C extends A implements X { }
B.
Class C implements Y extends B { }
C.
Class C extends A, B { }
D.
Class C implements X, Y extends B { }
E.
Class C extends B implements X, Y { }
Class C extends A implements X { }
Class C extends B implements X, Y { }
extends is for extending a class.
implements is for implementing an interface.
Java allows for a class to implement many interfaces.
Page 3 out of 26 Pages |
Previous |