Java Test With Answers
Java Test With Answers
5. Java is:
a) A programming language exclusively
b) A Java programming language, a development platform, a runtime
environment and a set of libraries for sophisticated program development.
c) A system for executing programs on different computer platforms
a) Checks that all its elements are valid Java words and their semantics.
b) Checks that all its elements are valid words in Java
c) Checks that all its elements are valid Java words, verifies the syntactic
structure of the program and its semantics.
a) False
b) True
12. The name of a Java element must comply with the rule:
13. In Java, variable and method names must begin with a lowercase letter. If the name is
compound, each word must begin with a capital letter.
a) False
b) True
14. In Java, class names must always begin with uppercase letters. If the name is
compound, each word must begin with a capital letter.
a) False
b) True
15. A data type indicates the values that a variable can store and the range of values it
supports.
a) False
b) True
a) False
b) True
18. Indicate the value of: x = -1 + 5 * 7 - 12 / 3
a) 28
b) 30
c) 6
a) 26
b) 30
c) 24
a) true
b) false
23. The attributes of an object can only store Java primitive types.
a) False
b) True
25. The constructor method is executed each time an object of the class is instantiated.
a) False
b) True
26. The state of an object can change during the execution of a Java program.
a) False
b) True
a) Attributes
b) Attributes and methods
c) Attributes and constructor methods
a) False
b) True
a) That the same method operates with parameters of different types or that the
same method receives a different list of parameters.
b) That the same method operates with parameters of different type
c) Different methods operate with different parameter types
int y= 0;
while (y<10){
System.out.println(y);
y++;
}
x=9 y=9
x=10 y=10
x=9 y=10
x=10 y=9
true
false
undefined
"i == 1"
System.out.println(x%y);
3
2
1
0
36. It is necessary to use the break statement in a switch structure for the program to
compile.
int k=3;
int m=2;
System.out.println ((m <= 99) & (k < m));
true
false
24
0111011
int x = 5;
int y = 5;
y /= ++x;
System.out.println(y);
6
5
1
0
40. What does the following program do?
int inc = 0;
int des = sWord.length()-1;
boolean bError = false;
z = x++ + y;
42. What does the following source code show on the screen?
int x=1;
switch (x) {
case 1:
System.out.println("One");
case 2:
System.out.println("Two");
case 3:
System.out.println("Three");
default:
System.out.println("Another number");
}
One
Two
Other number
One Two Three Other number
while (x<10) {
y += x;
x++;
}
System.out.println(y);
0
10
11
45
int x=1;
System.out.println(++x*4+1);
6
5
9
7
Sequential Structure
Repetitive Structure
Selective Structure
None of the above three.
System.out.println(12&13);
true
false
12
13
49. What is the result of the following operation?
System.out.println(5>>>1);
6
true
4
2
int x,counter;
counter = 10;
x = counter +1:
System.out.println("The value is " + x);
Selective Structure
Sequential Structure
Repetitive Structure
None of the above three.
Yes
No
Depends on Use
Compiler Dependent
while (y<x) {
x += y;
}
System.out.println(y);
0
1
10
None, enters infinite loop
if (counter<34) {
System.out.println("Counter is less than 24");
}
Sequential Structure
Repetitive Structure
Selective Structure
None of the above three.
x += 2;
4
"4"
4.0
Any of the three is valid
int i=1;
int j=2;
int k=3;
int m=2;
System.out.println ((j >= i) || (k == m));
true
false
undefined
Gives compilation error
import java.applet.Applet;
import java.awt.Graphics;
System.out.println(2+6>>>2);
8
5
4
2
Microsoft
Oracle
SUN Microsystems
Fujitsu
int k=3;
int m=2;
System.out.println ( !( k > m) );
3
true
2
False
int x = 10;
int y = 3;
x %= y;
System.out.println(y);
4
3
2
1
63. What does the following code statement do?
total -= --counter;
System.out.println("Hello World");
"Hello World"
"Hello World"
"Hello" and on another line "World".
"Hello" a tabulator and "World".
int x = 0;
int y = 0;
while (x<5) {
y +=x;
x++;
System.out.println(y);
10
5
0
The program does not compile
8 bit
16 bit
32 bit
64 bit
Math.poten
Operator ** Operator
Math.pow
Operator ^
68. What is displayed on the screen?
Numbers 1 to 9
The numbers from 0 to 9
Numbers from 1 to 10
The program does not compile
int j=2;
System.out.println ( j == 3 );
true
false
undefined
"j == 3"
byte
float
double
single
y *= x++;
System.out.println(x);
25
30
6
35
8 bit
16 bit
32 bit
64 bit
System.out.println(4<<<1);
5
8
true
3
75. Does source code One and source code Two do the same thing?
/* Code One*/
int x= 0;
do {
System.out.println(x);
x++;
} while (x<10);
/* Code Two */
int y= 0;
while (y<10){
System.out.println(y);
y++;
}
No, the first one shows from 1 to 10 and the second one from 0 to 9.
Yes, both show 0 to 9
No, the first one shows from 0 to 9 and the second one from 1 to 10.
Yes, both show from 1 to 10
int counter;
int x = 3;
counter += x;
System.out.println(counter);
3
1
0
The program does not compile
y *= x++;
System.out.println(y);
25
30
6
35
whole
decimals
character
all of the above
System.out.println
system.out.printer
System.out.prin
All are correct
whole
decimals
character
none of the above
yes
no
both with correct
none of the above
83. Do you use the if when you have 2 possible answers?
yes
no
both with correct
none of the above
84. The name of the class must be different from the package
yes
no
it does not matter
none of the above
A menu.
A list of items.
A receipt.
A shopping list.
92. It is a set of data and a set of operations that are performed on that data, what kind of
data you are talking about:
TDA.
Class.
Instance.
Object.
93. It is the action performed by an object when a message is passed or in response to a
change of state.
Behavior.
Execution.
Diffusion.
Instantiate.
Set.
UML.
Abstraction.
Data entry.
96. Communication occurs in the same way between an object and the objects it contains,
when objects need to interact, they do so through:
Sending codes.
Sending messages.
Sending coordinates.
Sending information.
97. Because object-oriented programming relies on them, these three pillars are like a
tower of bricks; remove the last brick and the whole thing falls apart. What are these
three pillars:
Abstraction, interface and encapsulation.
Interface, inheritance and abstraction.
Inheritance, polymorphism and encapsulation.
Abstraction, interface and polymorphism.
Attributes.
Class.
Methods.
Variables.
Directx
OpenGl
C++
new
abstract
public
private