Q. You want to create a table that looks like: 12 -9 8 7 14 -32 -1 0 Q. Which of
ID: 3855848 • Letter: Q
Question
Q. You want to create a table that looks like: 12 -9 8
7 14
-32 -1 0 Q.
Which of the following will work?
A. double[][] table = { 12, -9, 8, 7, 14, -32, -1, 0} ;
B. double[][] table = { {12, -9, 8}, {7, 14, 0}, -32, -1, 0} };
C. double[][] table = { {12, -9, 8} {7, 14} {-32, -1, 0} };
D. double[][] table = { {12, -9, 8}, {7, 14}, {-32, -1, 0} };
Q. Given: int[][] items = { {0, 1, 3, 4}, {4, 3, 99, 0, 7 }, {3, 2} } ; Which of the following fragments replaces row 0 of items with an entierly new row?
A. items[0][0] = 8; items[0][1] = 12; items[0][2] = 6;
B. items[0] = { 8, 12, 6 };
C. items[0] = new { 8, 12, 6 };
D. int[] temp = { 8, 12, 6 }; items[0] = temp;
Q. What must a non-abstract child do about an abstract method in its parent class?
A. A child must override an abstract method inherited from its parent by defining a method with the same signature and same return type.
B. A child must define an additional method similar to the one inherited from its parent by defining a method with the same signature and different return type. C. A child must not define any method with the same signature as the parent's abstract method.
D. A non-abstract child must define an abstract method with the same signature and same return type as the parent's abstract method.
Q. Can an interface name be used as the type of a variable, like this:
public static void main( String[] args ) {
SomeInterface x;
...
}
A. No—a variable must always be an object reference type.
B. No—a variable must always be an object reference type or a primitive type.
C. No—a variable must always be a primitive type.
D. Yes—the variable can refer to any object whose class implements the interface.
Q. Examine the following fragment:
String cat = "Hello"
cat += " ";
cat += "World" ;
How many objects are constructed?
A. 0
B. 1
C. 2
D. 3
Q. For each of the following code snippets, please indicate if the code shown would
a. fail to compile,
b. compile, but result in an error at runtime, or
c. execute without an error. In this case, indicate what output you would see.
public abstract class Plant {
public void smell() {
System.out.println(“No smell”);
}
}
public class Flower extends Plant {
public void smell() {
System.out.println(“I smell good!”);
}
}
public class Fruit extends Plant {
public void smell() {
System.out.println(“I smell yummy!”);
}
}
a. Flower rose = new Flower();
rose.smell();
Ans:
b. Fruit orange = new Fruit();
orange.smell();
Ans:
c. Plant oakTree = new Plant();
oakTree.smell();
Ans:
d. Plant banana = new Fruit();
banana.smell();
Ans:
e. Plant violet = new Flower();
Flower myViolet = violet;
myViolet.smell();
Ans:
Q. Consider the following two classes:
public class ClassA {
public void methodOne(int i) {
}
public void methodTwo(int i) {
}
public static void methodThree(int i) {
}
public static void methodFour(int i) {
}
}
public class ClassB extends ClassA {
public static void methodOne(int i) {
}
public void methodTwo(int i) {
}
public void methodThree(int i) {
}
public static void methodFour(int i) {
}
}
Question 1a: Which method overrides a method in the superclass?
Answer 1a:
Question 1b: Which method hides a method in the superclass?
Answer 1b:
Question 1c: What do the other methods do?
Answer 1c:
Q. Consider the following classes to trace the output:
public class A{
A(){
System.out.println(“A”);
}
}
public class B extends A{
B(){
System.out.println(“B”);
}
}
public class C extends B{
C(){
System.out.println(“C”);
}
}
public class Tester{
public static void main(String [] args){
A a = new A();
C c = new C();
B b = new B();
}
} Output:
Q. Consider the following classes to trace the output:
interface Testable {
abstract public void test();
}
abstract class A {
public void inA(){
System.out.println("In a method");
}
abstract public void method1();
}
public class HelloWorld extends A implements Testable{
public void method1(){
System.out.println("In method1");
}
public void test(){
System.out.println("delicious!");
}
public static void main(String [] args){
A a = new HelloWorld();
a.method1();
a.inA();
Testable t = (HelloWorld)a;
t.test();
}
}
Output:
Explanation / Answer
1.D. double[][] table = { {12, -9, 8}, {7, 14}, {-32, -1, 0} };
2D.int[] temp = { 8, 12, 6 }; items[0] = temp;
3.A. A child must override an abstract method inherited from its parent by defining a method with the same signature and same return type.
4.D.Yes—the variable can refer to any object whose class implements the interface.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.