Question
Given the following code, what is output by the method call, mystery(6 * 8)? public static void mystery (int x[]) { System.out.println(A); } public static
Given the following code, what is output by the method call, mystery(6 * 8)?
public static void mystery (int x[]) { System.out.println("A"); } public static void mystery (int x) { System.out.println("B"); } public static void mystery (String x) { System.out.println("C"); }
B
CA
C
A
CB
Question 2
Which of the following is true about overloaded methods?
You can only overload methods that have parameters.
Java cannot use a method's return type to tell two overloaded methods apart.
Java cannot use a method's parameters to tell two overloaded methods apart.
None of the items listed.
All overloaded methods must have different names.
Question 3
Given the following code, what is output by the method call, mystery (5, 7.0015)?
public static void mystery (int a) { System.out.println("A"); } public static void mystery (double a) { System.out.println("B"); } public static void mystery (int a, double b) { System.out.println("C"); } public static void mystery (double a, int b) { System.out.println("D"); }
C
D
Nothing is printed - there is an error.
B
A
Question 4
Consider the following methods:
public static double doStuff(int a) { return a/2; } public static double doStuff(double val) { return val/10; }
What is output by the following?
System.out.println(doStuff(5) + doStuff(5.0));
5
2.50.5
2.00.5
22.5
2.5
Flag this Question
Question 5
What is output to the screen by the following code?
System.out.println("Sum=" + 4 + 5);
Sum= 5 4
Sum=45
Sum=9
Sum=54
Sum= 4 5
Question 6
What is output to the screen by the following code?
System.out.print(21/5);
4
5.5
5
3.5
4.2
Question 7
Consider the following three classes: Clothing, Socks, and Sweater. Which would you choose be an abstract class?
All of the items listed.
Socks
Sweater
Socks and Sweater
Clothing
Question 8
Which of the following keywords allows a child class to access the overridden methods in a parent class?
super
extends
this
None of the answers listed.
new
Question 9
Questions 9 and 10 refer to the following code:
public abstract class Phone { abstract void dial(); } public class MobilePhone extends Phone { } public class RotaryPhone extends Phone { public void dial () { //code not shown } }
Which of the following statements is true?
Neither can be instantiated since they do not include constructors.
Neither can be instantiated since you cannot extend an abstract class.
MobilePhone can be instantiated.
RotaryPhone cannot be instantiated.
RotaryPhone can be instantiated.
Question 10
Which of the following statements is true?
A Phone object can access methods in MobilePhone.
A RotaryPhone object can access methods in MobilePhone.
RotaryPhone inherits from Phone and MobilePhone.
RotaryPhone inherits from Phone.
None of the answers listed.
Question 11
Suppose a class implements the Comparable interface. Which of the following methods must the class include?
charAt
substring
compareTo
length
indexOf
Question 12
Questions 12-14 refer to the following:
public class A { public A () { System.out.print(one ); } public A (int z) { System.out.print(two ); } public void doStuff() { System.out.print(six ); } } public class B extends A { public B () { super (); System.out.print(three ); } public B (int val) { super (val); System.out.print(four ); } }
What is printed when the following line of code is executed?
B b = new B();
three two
one three
four two
two four
one four
Question 13
What is printed when the following line of code is executed?
A a = new B(5);
two
four
one
four one
two four
Question 14
Assume that variable b has been instantiated as a B object. What is printed when the following line of code is executed?
b.doStuff();
two
five
four
three
six
Flag this Question
Question 15
Which of the following is true about interfaces:
An interface can have only non abstract methods.
All methods in an interface must be abstract.
A class can only implement one interface.
None of the items listed.
Can not contain constants but can have variables.
Question 16
What is the rule for a super reference in a constructor?
It must be in the parent class' constructor.
You cannot use super in a constructor.
It must be the last line of the constructor in the child class.
Only one child class can use it.
It must be the first line of the constructor in the child class.
Question 17
Consider the following class definition.
public class WhatsIt { private int length; private int width; public int getArea () { // implementation not shown } private int getPerimeter () { // implementation not shown } }
A child class Thingy that extends WhatsIt would have access to:
width, length, getPerimeter()
getPerimeter()
All of the items listed.
getArea()
width, length, getArea()
Question 18
Questions 18 - 20 pertain to the following class, Point:
public class Point { private double x; private double y; public Point() { this (0, 0); } public Point(double a, double b) { /* missing code */ } // ... other methods not shown }
Which of the following correctly implements the equals method?
public boolean equals(Point p) { return (x == p.x && y == p.y ); }
public void equals(Point p) { System.out.println(x == p.x && y == p.y); }
public void equals(Point p) { return (x == p.x && y == p.y ); }
public boolean equals(Point p) { return (x == Point.x && y == Point.y); }
public boolean equals(Point p) { System.out.println(x == p.x && y == p.y); }
Question 19
The default constructor sets x and y to (0, 0) by calling the second constructor. What could be used to replace /* missing code */ so that this works as intended?
a = 0; b = 0;
this (x, y);
this(0, 0);
x = a; y = b;
a = x; b = y;
Question 20
Which of the following correctly implements a mutator method for Point?
public double getX() { return x; }
public void setCoordinates (double a, double b) { x = a; y = b; }
None of the items listed.
public double getX() { return a; }
public void setCoordinates (double a, double b) { Point p = new Point(a,b); }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started