Access over 20 million homework & study documents

3 1 What is the output of running the class Test in the following co

Content type
User Generated
Rating
Showing Page:
1/5
3.1 What is 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\");
}
}
a. Nothing.
b is an instance of A.
b is an instance of C.
b is an instance of A followed by b is an instance of C.
3.2 What 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);
}
}

Sign up to view the full document!

lock_open Sign Up
Showing Page:
2/5
public class C {
public static void main(String[] args) {
B b = new B(\"The constructor of B is invoked\"); }
}
none
\"The constructor of B is invoked\"
\"The default constructor of A is invoked\" \"The
constructor of B is invoked\"
\"The default constructor of A is invoked\"
3.3 Given the following code.
public class Test1 {
public Object max(Object o1, Object o2) { if
((Comparable)o1.compareTo(o2) >= 0) { return o1;
} else { return o2;
}
}
}
The program has a syntax error because Test1 does not
have a main method.
The program has a syntax error because o1 is an Object
instance and it does not have the compareTo method.
The program has a syntax error because you cannot cast
an Object instance o1 into
Comparable.
The program would compile if
((Comparable)o1.compareTo(o2) >= 0) is replaced by
(((Comparable)o1).compareTo(o2) >= 0). e. b and d are
both correct.
3.4 Which of the following statements regarding abstract
methods is not true?

Sign up to view the full document!

lock_open Sign Up
Showing Page:
3/5

Sign up to view the full document!

lock_open Sign Up
End of Preview - Want to read all 5 pages?
Access Now
Unformatted Attachment Preview
3.1 What is the output of running the class Test in the following code? interface A { } class C {} void print(); 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\"); } } a. b is b is b is Nothing. an instance of A. an instance of C. an instance of A followed by b is an instance of C. 3.2 What 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 \"); } none \"The constructor of B is invoked \" \"The default constructor of A is invoked \" \"The constructor of B is invoked\" \"The default constructor of A is invoked\" 3.3 Given the following code. public class Test1 { public Object max(Object o1, Object o2) { ((Comparable)o1.compareTo(o2) >= 0) { } else { return o2; } } } } if return o1; The program has a syntax error because Test1 does not have a main method. The program has a syntax error because o1 is an Object instance and it does not have the compareTo method. The program has a syntax error because you cannot cast an Object instance o1 into Comparable. The program would compile if ((Comparable)o1.compareTo(o2) ...
Purchase document to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Anonymous
This is great! Exactly what I wanted.

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4