×
Develop a quiz
Write fanfiction
My tests
Categories
▼
Actors
Books
Career / Job
Cartoons / Mangas
Celebrities
Children / Kids
EQ Tests
Fan
Fan Fiction
Games
Health
IQ Tests
Knowledge
Language
Love Tests
Movies
Music
Only for Men
Only for Women
Personality
Purity Tests
Satire / Irony / Fun
Series / Shows
Social Media stars
Sport
Think / Memory
Top 10 lists
New Tests
Images galleries
Categories
Actors
Books
Career / Job
Cartoons / Mangas
Celebrities
Children / Kids
EQ Tests
Fan
Fan Fiction
Games
Health
IQ Tests
Knowledge
Language
Love Tests
Movies
Music
Only for Men
Only for Women
Personality
Purity Tests
Satire / Irony / Fun
Series / Shows
Social Media stars
Sport
Think / Memory
Top 10 lists
New Tests
Images galleries
Create
Develop a quiz
My tests
Write a fanfiction
Knowledge / Trivia tests
-»
Computers / Internet
-»
Programming
JAVA
50 Questions - Developed by:
Elisabeth
- Developed on:
2013-12-15
- 45,106 taken - 2 people like it
1
Suppose s is a string with the value "java. What will be assigned to x if you execute the following code?
'v'
Nothing will be assigned to x, because the execution causes the runtime error StringIndexOutofBoundsException
'a'
2
Which of the following statements is preferred to create a string "Welcome to Java"?
String s; s = new String("Welcome to Java");
String s = "Welcome to Java";
String s; s = "Welcome to Java";
String s = new String("Welcome to Java");
3
What is the output of the following code?
public class Test {
public static void main(String[] args) {
String s1 = "Welcome to Java!";
String s2 = s1;
if (s1 == s2)
System.out.println("s1 and s2 reference to the same String object");
System.out.println("s1 and s2 reference to different String objects");
}
}
None
S1 and s2 reference to different String object
S1 and s2 reference to the same String object
4
What is the output of the following code?
public class Test {
public static void main(String[ ] args) {
String s1 = "Welcome to Java!";
String s2 = "Welcome to Java!";
if (s1 == s2)
System.out.println("s1 and s2 reference to the same String object");
else
System.out.println("s1 and s2 reference to different String objects");
}
}
S1 and s2 reference to different String objects
s1 and s2 reference to the same String object
None
5
What is the output of the following code?
String s = "University";
s.replace("i", "ABC");
System.out.println(s);
UnABCversity
UniversABCty
University
UnABCversABCty
6
What is the printout for the first println statement in the main method?
public class Foo {
static int I = 0;
static int j = 0;
public static void main(String[ ] args) {
int I = 2;
int k = 3;
{
int j = 3;
System.out.println("i + j is " + I + j);
}
k = I + j;
System.out.println("k is " + k);
System.out.println("j is " + j);
}
}
I + j is 6
I + j is 23
I + j is 5
I + j is 22
7
What is the return value of "SELECT".substring(0, 5)?
"SELE"
"SELEC"
"ELECT"
"SELECT"
8
Which of the following is the correct statement to return JAVA?
"Java".toUpperCase()
String.toUpperCase("Java")
ToUpperCase("Java")
"Java".toUpperCase("Java")
9
You can declare two variables with the same name in ____.
A block
A method one as a formal parameter and the other as a local variable
Two nested blocks in a method (two nested blocks means one being inside the other)
Different methods in a class
10
Analyze the following code.
int[ ] list = new int[5];
list = new int[6];
The code can compile and run fine. The second line assigns a new array to list.
The code has runtime errors because the variable list cannot be changed once it is assigned.
The code has compile errors because the variable list cannot be changed once it is assigned.
The code has compile errors because you cannot assign a different size array to list.
11
Analyze the following code.
public class Test {
public static void main(String[ ] args) {
int[ ] x = new int[3];
System.out.println("x[0] is " + x[0]);
}
}
The program runs fine and displays x[0] is 0
The program has a runtime error because the array elements are not initialized.
The program has a runtime error because the array element x[0] is not defined.
The program has a compile error because the size of the array wasn't specified when declaring the array.
12
Analyze the following code:
public class Test {
public static void main(String[ ] args) {
int[ ] oldList = {1, 2, 3, 4, 5};
reverse(oldList);
for (int I = 0; I < oldList.length; i++)
System.out.print(oldList[i] + " ");
}
public static void reverse(int[ ] list) {
int[ ] newList = new int[list.length];
for (int I = 0; I < list.length; i++)
newList[i] = list[list.length - 1 - i];
list = newList;
}
}
The program displays 5 4 3 2 1.
The program displays 1 2 3 4 5.
The program displays 5 4 3 2 1 and then raises an ArrayIndexOutOfBoundsException.
The program displays 1 2 3 4 5 and then raises an ArrayIndexOutOfBoundsException.
13
How many elements are in array double[ ] list = new double[5]?
6
0
5
4
14
If you declare an array double[ ] list = {3.4, 2.0, 3.5, 5.5}, list[1] is ________.
3.4
Undefined
2.0
5.5
15
If you declare an array double[ ] list = {3.4, 2.0, 3.5, 5.5}, the highest index in array list is ________.
3
4
1
0
2
16
The JVM stores the array in an area of memory, called ________, which is used for dynamic memory allocation where blocks of memory are allocated and freed in an arbitrary order.
Memory block
Stack
Dynamic memory
Heap
17
When invoking a method with an object argument, ________ is passed.
The object is copied, then the reference of the copied object
the contents of the object
A copy of the object
The reference of the object
18
When you pass an array to a method, the method receives ________.
A copy of the array
The reference of the array
The length of the array
A copy of the first element
19
The selectionSort method is defined in this section. What is list1 after executing the following statements?
double[ ] list1 = {3.1, 3.1, 2.5, 6.4};
selectionSort(list1);
List1 is 6.4, 3.1, 3.1, 2.5
List1 is 3.1, 2.5, 3.1, 6.4
List1 is 2.5 3.1, 3.1, 6.4
List1 is 3.1, 3.1, 2.5, 6.4
20
An object is an instance of a ________.
Class
Data
Method
Program
21
A method that is associated with an individual object is called ________.
A static method
An object method
An instance method
A class method
22
Given the declaration Circle x = new Circle(), which of the following statement is most accurate?
X contains a reference to a Circle object.
You can assign an int value to x
X contains an int value
X contains an object of the Circle type
23
Given the declaration Circle[ ] x = new Circle[10], which of the following statement is most accurate?
x contains a reference to an array and each element in the array can hold a Circle object.
X contains an array of ten objects of the Circle type.
x contains a reference to an array and each element in the array can hold a reference to a Circle object.
X contains an array of ten int values.
24
The keyword ________ is required to declare a class.
All of the answers
Private
Public
Class
25
To declare a constant MAX_LENGTH as a member of the class, you write
Static double MAX_LENGTH = 99.98;
final static double MAX_LENGTH = 99.98;
final static float MAX_LENGTH = 99.98;
Final static MAX_LENGTH = 99.98;
Final double MAX_LENGTH = 99.98;
26
When you return an array from a method, the method returns ________.
A copy of the first element
The length of the array
The reference of the array
A copy of the array
27
________ is a construct that defines objects of the same type.
A data field
A class
A method
An object
28
________ is invoked to create an object.
The main method
A method with the void return type
A constructor
A method with a return type
29
________ represents an entity in the real world that can be distinctly identified.
A data field
An object
A class
A method
30
Suppose x = 1, y = -1, and z = 1. What is the printout of the following statement?
if (x > 0)
if (y > 0)
System.out.println("x > 0 and y > 0");
else if (z > 0)
System.out.println("x < 0 and z > 0");
No printout.
X < 0 and z > 0;
X > 0 and y > 0;
X < 0 and z < 0;
31
The "less than or equal to" comparison operator in Java is ________.
=>
!=
<=
<<
32
The equal comparison operator in Java is ________.
^=
<>
!=
==
33
The following code displays ________.
double temperature = 50;
if (temperature >= 100)
System.out.println("too hot");
else if (temperature <= 40)
System.out.println("too cold");
else
System.out.println("just right");
Too hot
Just right
Too hot too cold just right
Too cold
34
What is 1 + 1 + 1 + 1 + 1 == 5?
True
False
There is no guarantee that 1 + 1 + 1 + 1 + 1 == 5
35
What is the output of the following code?
boolean even = false;
System.out.println((even? "true": "false"));
Nothing
True
False
True false
36
What is the printout of the following switch statement?
char ch = 'b';
switch (ch) {
case 'a':
System.out.print(ch);
case 'b':
System.out.print(ch);
case 'c':
System.out.print(ch);
case 'd':
System.out.print(ch);
}
B
Bcd
Bbb
Abcd
Bb
37
Which of the following code displays the area of a circle if the radius is positive?
If (radius <= 0) System.out.println(radius * radius * 3.14159);
If (radius > 0) System.out.println(radius * radius * 3.14159);
If (radius!= 0) System.out.println(radius * radius * 3.14159);
If (radius >= 0) System.out.println(radius * radius * 3.14159);
38
Which of the following is the correct expression that evaluates to true if the number x is between 1 and 100 or the number is negative?
1 < x < 100 && x < 0
((x < 100) && (x > 1)) || (x < 0)
((x < 100) && (x > 1)) && (x < 0)
(1 > x > 100) || (x < 0)
39
Analyze the following fragment:
double sum = 0;
double d = 0;
while (d!= 10.0) {
d += 0.1;
sum += sum + d;
}
The program never stops because d is always 0.1 inside the loop.
He program does not compile because sum and d are declared double, but assigned with integer value 0.
After the loop, sum is 0 + 0.1 + 0.2 + 0.3 + ... + 1.9
He program may not stop because of the phenomenon referred to as numerical inaccuracy for operating with floating-point numbers.
40
Do the following two statements in (I) and (II) result in the same value in sum?
(I):
for (int I = 0; i<10; ++i) {
sum += i;
}
(II):
for (int I = 0; i<10; i++) {
sum += i;
}
No
Yes
Dont know
41
How many times will the following code print "Welcome to Java"?
int count = 0;
while (count < 10) {
System.out.println("Welcome to Java");
count++;
}
10
8
9
11
0
42
How many times will the following code print "Welcome to Java"?
int count = 0;
do {
System.out.println("Welcome to Java");
count++;
} while (count < 10);
8
9
0
10
11
43
What is the number of iterations in the following loop:
for (int I = 1; I <= n; i++) {
// iteration
}
N
N - 1
2*n
N + 1
44
What is the output for y?
int y = 0;
for (int I = 0; i<10; ++i) {
y += i;
}
System.out.println(y);
13
45
11
12
10
45
Will the following program terminate?
int balance = 10;
while (true) {
if (balance < 9) continue;
balance = balance - 9;
}
No
Yes
Dk
46
Why do computers use zeros and ones?
Because binary numbers are simplest.
Because binary numbers are the bases upon which all other number systems are built.
Because digital devices have two stable states and it is natural to use one state for 0 and the other for 1
Because combinations of zeros and ones can represent any numbers and characters.
47
________ consists of a set of separate programs for developing and testing Java programs, each of which is invoked from a command line.
Java IDE
Java language specification
Java API
Java JDK
48
Analyze the following code.
import javax.swing.*;
public class ShowErrors {
public static void main(String[ ] args) {
int i;
int j;
String s = JOptionPane.showInputDialog(null, "Enter an integer", "Input",
JOptionPane.QUESTION_MESSAGE);
j = Integer.parseInt(s);
I = (i + 4);
}
}
The program cannot compile because I does not have an initial value when it is used in I = I + 4;
The program compiles and runs fine
He program compiles but has a runtime error because I does not have an initial value when it is used in I = I + 4;
The program cannot compile because j is not initialized.
49
Analyze the following code.
public class Test {
public static void main(String[ ] args) {
int month = 09;
System.out.println("month is " + month);
}
}
The program displays month is 9
The program displays month is 09
The program has a syntax error, because 09 is an incorrect literal value.
The program displays month is 9.0
50
If you enter 1 2 3, when you run this program, what will be the output?
import java.util.Scanner;
public class Test1 {
public static void main(String[ ] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter three numbers: ");
double number1 = input.nextDouble();
double number2 = input.nextDouble();
double number3 = input.nextDouble();
// Compute average
double average = (number1 + number2 + number3) / 3;
// Display result
System.out.println(average);
}
}
3.0
2.0
4.0
1.0
Comments (0)
autorenew
Please leave empty:
Please leave empty:
Please leave empty:
Change color
navy
blue
teal
olive
green
maroon
red
purple
fuchsia
gray
B
I
U
large
tiny
×
Are you sure you want to delete this comment?
Delete this comment
Cancel
Are you sure you want to delete this comment?