Quiz
Chapters 12 and 13
Erstelle ein kostenloses Konto, um dieses Quiz zu beenden
Speichere deinen Fortschritt und sieh dir dein Endergebnis an.
oder mit deiner E-Mail registrieren
Schon ein Konto? Anmelden
Fragen in diesem Quiz (11)
1The output from the following code is __________.
java.util.ArrayList<String> list = new java.util.ArrayList<>();
list.add("New York");
java.util.ArrayList<String> list1 = (java.util.ArrayList<String>)(list.clone());
list.add("Atlanta");
list1.add("Dallas");
System.out.println(list);- A[New York]
- B[New York, Atlanta]
- C[New York, Atlanta, Dallas]
- D[New York, Dallas]
2Show the output of running the class Test in the following code:
interface A {
void print();
}
class C {}
class B extends C implements A {
public void print() { }
}
public class Test {
public static void main(String[] args) {
B b = new B();
if (b instanceof A)
System.out.println("b is an instance of A");
if (b instanceof C)
System.out.println("b is an instance of C");
}
}- ANothing.
- Bb is an instance of A.
- Cb is an instance of C.
- Db is an instance of A followed by b is an instance of C.
3Suppose A is an interface, B is an abstract class that partial implements A, and A is a concrete class with a default constructor that extends B. Which of the following is correct?
- AA a = new A();
- BA a = new B();
- CB b = new A();
- DB b = new B();
4Which of the following is correct?
- AAn abstract class does not contain constructors.
- BThe constructors in an abstract class should be protected.
- CThe constructors in an abstract class are private.
- DYou may declare a final abstract class.
- EAn interface may contain constructors.
5What is the output of running class C?
class A {
public A() {
System.out.println(
"The default constructor of A is invoked");
}
}
class B extends A {
public B(String s) {
System.out.println(s);
}
}
public class C {
public static void main(String[] args) {
B b = new B("The constructor of B is invoked");
}
}- Anone
- B"The constructor of B is invoked"
- C"The default constructor of A is invoked" "The constructor of B is invoked"
- D"The default constructor of A is invoked"
6Analyze the following code:
public class Test1 {
public Object max(Object o1, Object o2) {
if ((Comparable)o1.compareTo(o2) >= 0) {
return o1;
}
else {
return o2;
}
}
}- AThe program has a syntax error because Test1 does not have a main method.
- BThe program has a syntax error because o1 is an Object instance and it does not have the compareTo method.
- CThe program has a syntax error because you cannot cast an Object instance o1 into Comparable.
- DThe program would compile if ((Comparable)o1.compareTo(o2) >= 0)
is replaced by (((Comparable)o1).compareTo(o2) >= 0). - Eb and d are both correct.
7Which of the following statements regarding abstract methods is not true?
- AAn abstract class can have instances created using the constructor of the abstract class.
- BAn abstract class can be extended.
- CA subclass of a non-abstract superclass can be abstract.
- DA subclass can override a concrete method in a superclass to declare it abstract.
- EAn abstract class can be used as a data type.
8Which of the following possible modifications will fix the errors in this code?
public class Test {
private double code;
public double getCode() {
return code;
}
protected abstract void setCode(double code);
}- ARemove abstract in the setCode method declaration.
- BChange protected to public.
- CAdd abstract in the class declaration.
- Db and c.
9Analyze the following code.
class Test {
public static void main(String[] args) {
Object x = new Integer(2);
System.out.println(x.toString());
}
}- AThe program has syntax errors because an Integer object is assigned to x.
- BWhen x.toString() is invoked, the toString() method in the Object class is used.
- CWhen x.toString() is invoked, the toString() method in the Integer class is used.
- DNone of the above.
10What exception type does the following program throw?
public class Test {
public static void main(String[] args) {
Object o = new Object();
String d = (String)o;
}
}- AArithmeticException
- BNo exception
- CStringIndexOutOfBoundsException
- DArrayIndexOutOfBoundsException
- EClassCastException
11What exception type does the following program throw?
public class Test {
public static void main(String[] args) {
Object o = null;
System.out.println(o.toString());
}
}- AArrayIndexOutOfBoundsException
- BClassCastException
- CNullPointerException
- DArithmeticException
- EStringIndexOutOfBoundsException
Informationen
- Beschreibung
- CS 110 Quiz am Chapters 12 and 13, erstellt von Phil McCallion am 16/07/2017.
- Autor
- Phil McCallion
- Sprache
- English
- Aufrufe
- 2
- Schlagwörter
- Bewertung
- Noch keine Bewertungen Bewerte dieses Quiz