switch (val)
{
case 1:
System.out.print( “P” );
case 2:
case 3:
System.out.print( “Q” );
break;
case 4:
System.out.print( “R” );
default:
System.out.print( “S” );
}
What is the output?
A.
PQS
B.
PQ
C.
S
D.
P
4 points
Question 2
How many times will “hello” be printed by the following:
for (int i = 0; i < 10; i++)
System.out.println(“hello”);
A.
9
B.
0
C.
11
D.
10
4 points
Question 3
When writing a subclass, which of all of the following are true?
A.
You can override methods of the superclass
B.
You can inherit methods from the superclass
C.
You can define new methods in the subclass
D.
All of the above
4 points
Question 4
Select the best answer.
Local variables are destroyed when
A.
the constructor runs
B.
you explicitly delete them
C.
the object is no longer in use
D.
the method ends
4 points
Question 5
Which of the following is a valid constructor method header for a class named Car?
A.
Public Class Car
B.
public car(String model)
C.
public class Car(String model)
D.
public Car(String model)
4 points
Question 6
For the code:
int m = 0;
while (m++ < 2)
System.out.print(m + ” “);
What is the output?
A.
0 1 2
B.
1 2
C.
1
D.
0 1
4 points
Question 7
Remember that the % operator evaluates to the remainder after integer division e.g. 8 % 4 is 0, 11 % 4 is 3. What is the value of x after the following?
int x = 0;
for (int i = 1; i < 6; ++i)
if (i % 2 == 0)
x = x + i;
A.
0
B.
6
C.
15
D.
21
4 points
Question 8
Select the best answer.
The main purpose of a constructor is to
A.
Initialize instance variables
B.
Name the method
C.
Construct a method
D.
Return a value
4 points
Question 9
Given the following class definition:
public class Car
{
private double fuelLevel;
public Car(double gallons)
{
fuelLevel = gallons;
}
public void addGas(double gallons)
{
fuelLevel += gallons;
}
}
and this code segment:
Car car1 = new Car(20);
Car car2 = car1;
car2.addGas(10);
What is the value stored in fuelLevel for car1?
A.
20.0
B.
0.0
C.
10.0
D.
30.0
4 points
Question 10
Assume that val has been declared as an int for the code below:
if (val >= 4)
System.out.println(“Test A”);
else if (val > 9)
System.out.println(“Test B”);
else
System.out. println(“Test C”);
Which one of the alternatives below will result in “Test C” being printed:
A.
val is 4
B.
no values of val will do this
C.
val < 4
D.
val between 4 and 9
4 points
Question 11
Given
int quantity = 3;
double value = 7.52;
String number = “one”;
Which of all of the following are valid assignments?
A.
quantity = value;
B.
quantity = (int)value;
C.
value = quantity;
D.
quantity = (double)value;
E.
quantity = number;
F.
Both B and C
4 points
Question 12
Select the best answer.
A(n) ____ can add instance variables and methods to an existing class.
A.
subclass
B.
polymorphism
C.
superclass
D.
constructor
4 points
Question 13
What is the error in the following code fragment?
double data[] = new double[20];
data[20] = 15.25;
A.
Out-of-bounds error
B.
Data not initialized
C.
A two-dimensional array is required
D.
A cast is required
4 points
Question 14
If you know that your loop must iterate at least one time, it is recommended that you use a _________ loop
A.
do _ while
B.
repeat
C.
for
D.
while
4 points
Question 15
Multiplying an int (such as 5) by a double (such as 0.1) gives
A.
an exception is thrown
B.
an int
C.
an error
D.
a double
4 points
Question 16
After executing this code segment:
double v1 = 2000.0;
double v2 = v1;
v2 = v2 + 500.0;
What will be the value of v1 ?
A.
Unknown
B.
2000.0
C.
2500.0
D.
0.0
4 points
Question 17
Which of the following indicates that a method does not return a value?
A.
double
B.
static
C.
void
D.
public
4 points
Question 18
Where an inherited method is overridden, the type of the actual object, not the type of the reference to the object is used to determine which method to call?
True
False
4 points
Question 19
The compiler will generate an error if the same name but different signature is used for more than one method or constructor.
True
False
4 points
Question 20
Given this code fragment:
{
int x = 5, y = 6, z = 7;
foo(x, y, z);
System.out.println(x + “, ” + y + “, ” + z);
}
public void foo(int a, int b, int c)
{
a = a + 3;
b = a + c;
c = c + b;
}
What is the output?
A.
5, 6, 7
B.
8, 12, 13
C.
2, 0, 4
D.
8, 15, 22
4 points
Question 21
javadoc comments begin and end with:
A.
// and //
B.
/* and */
C.
/** and */
D.
/@ and @/
4 points
Question 22
When using the BlueJ debugger, a class must be compiled before you can set a break point in it?
True
False
4 points
Question 23
Which of the following are Java naming conventions?
#1: Classes start with an uppercase letter
#2: Methods start with an uppercase letter
#3: Object start with a lowercase letter
#4: Objects start with an uppercase letter
#5: Classes start with a lowercase letter
#6: Methods start with a lowercase letter
A.
#1, #3 and #6
B.
#4, #5 and #6
C.
#1, #2 and #4
D.
#3, #5 and #6
4 points
Question 24
Given the array
double cost[] = new double[5];
How would you access the last element of the array?
A.
cost.get(4)
B.
cost[4]
C.
cost.get[5]
D.
cost[5]
4 points
Question 25
In a program, you create an object of a class using the keyword ____ .
A.
abstract
B.
extends
C.
create
D.
new
4 points
Save and Submit
Click Save and Submit to save and submit. Click Save All Answers to save all answers.
Try it now!
How it works?
Follow these simple steps to get your paper done
Place your order
Fill in the order form and provide all details of your assignment.
Proceed with the payment
Choose the payment system that suits you most.
Receive the final file
Once your paper is ready, we will email it to you.
Our Services
Quality Essay Help has stood as the world’s leading custom essay writing services providers. Once you enter all the details in the order form under the place order button, the rest is up to us.
Essays
At Quality Essay Help, we prioritize on all aspects that bring about a good grade such as impeccable grammar, proper structure, zero-plagiarism and conformance to guidelines. Our experienced team of writers will help you completed your essays and other assignments.
Admissions
Admission and Business Papers
Be assured that you’ll definitely get accepted to the Master’s level program at any university once you enter all the details in the order form. We won’t leave you here; we will also help you secure a good position in your aspired workplace by creating an outstanding resume or portfolio once you place an order.
Editing
Editing and Proofreading
Our skilled editing and writing team will help you restructure you paper, paraphrase, correct grammar and replace plagiarized sections on your paper just on time. The service is geared toward eliminating any mistakes and rather enhancing better quality.
Coursework
Technical papers
We have writers in almost all fields including the most technical fields. You don’t have to worry about the complexity of your paper. Simply enter as much details as possible in the place order section.