Show the output of running the class Test in the following codelines: interface
ID: 3610861 • Letter: S
Question
Show the output of running the class Test in the following codelines:
interface A {
}
class C {
}
class B extends D implements A {
}
public class Test extends Thread {
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");
}
}
class D extends C {
}
A) b is an instance of A.
B) b is an instance of A followed by b is an instance of C.
C) b is an instance of C.
D) Nothing.
2. Analyze the following code.
public class Test {
public static void main(String[ ] args) {
Fruit[ ] fruits = {new Fruit(2), new Fruit(3), new Fruit(1)};
Java. util. Arrays. sort(fruits);
}
}
class Fruit {
private double weight;
public Fruit(double weight) {
this.weight = weight;
}
}
A) The program has a syntax error because the Fruit class does nothave a default constructor.
B) The program has a runtime error on Line 3 because the Fruitclass does not have a default constructor.
C) The program has a syntax error on Line 4 because the Fruit classdoes not implement the Java.lang.Comparable interface and the Fruitobjects are not comparable.
D) The program has a runtime error on Line 4 because the Fruitclass does not implement the Java.lang.Comparable interface and theFruit objects are not comparable.
Explanation / Answer
It is 1) b 2) d
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.