Java MCQ
Java MCQ
Assume that File is an abstract class and has toFile() method. ImageFile and
BinaryFile are concrete classes of the abstract class File.
Also, assume that the method toFile() is implemented in both Binary File and
Image File. A File references an ImageFile object in memory and the toFile
method is called, which implementation method will be called?
Binary File
Image File
A class can have many methods with the same name as long as the number of
parameters or type of parameters is different. This OOP concept is known as
Method
Invocating
Method
Overriding
Method Labeling
Method
Overloading
Which of the following is considered as a blue print that defines the variables and
methods common to all of its objects of a specific kind?
Object
Class
Method
Real data
types
Significant Digits,
Exponent
Length, Denominator
Mode, Numerator
String str;
int fname;
str = "Foolish boy.";
fname = str.indexOf("fool");
-1
What is the value of ‘number’ after the following code fragment execution?
int number = 0;
int number2 = 12
while (number < number2)
{
number = number + 1;
}
12
21
13
Given the following code snippet;
int salaries[];
int index = 0;
salaries = new int salaries[4];
while (index < 4)
{
salaries[index] = 10000;
index++;
}
What is the value of salaries [3]?
4000
0
5000
0
1500
0
1000
0
boolea
n
void
public
Button
25,
byte
17, int
25, int
float
doubl
e
Float
Doubl
e
Assume that the value 3929.92 is of type ‘float’. How to assign this value after
declaring the variable ‘interest’ of type float?
interest = 3929.92
interest =
(Float)3929.92
interest = 3929.92
(float)
interest = 3929.92f
package payroll;package
admindept;
import payroll.*;
package
payroll.admindept.Sample;
import payroll.admindept.*;
package payroll.admindept;
extends Throwable
implements
Throwable
serializable
All the wrapper classes (Integer, Boolean, Float, Short, Long, Double and
Character) in java
are private
are
serializable
are
immutatable
are final
he code snippet
will
compile and display
“Equal”
Consider the following code snippet. What will be assigned to the variable
fourthChar, if the code is executed?
‘a’
‘v’
throws
StringIndexOutofBoundsException
null characater
Non daemon
thread
Daemon thread
When a thread terminates its processing, into what state that thread enters?
Running
state
Waiting
state
Dead state
Beginning s
0. Which statement is true?
LinkedList is a subclass of
ArrayList
start()
run()
wait()
notify() and
notifyAll()
A thread which has invoked wait() method of an object, still owns the lock of the
object. Is this statement true or false?
True
Fals
e
DataInputStream is an example of
Output
stream
I/O stream
Filtered
stream
File stream
2. A lower precision can be assigned to a higher precision value in Java. For example a byte type data
can be assigned to int type.
Correct
7. Assume that File is an abstract class and has toFile() method. ImageFile and BinaryFile are concrete
classes of the abstract class File.
Also, assume that the method toFile() is implemented in both Binary File and Image File. A File
references an ImageFile object in memory and the toFile method is called, which implementation method
will be called?
Correct
8. A class can have many methods with the same name as long as the number of parameters or type of
parameters is different. This OOP concept is known as
You answered: Method Labeling
Incorrect
9. Which of the following is considered as a blue print that defines the variables and methods common to
all of its objects of a specific kind?
Correct
11. After the following code fragment, what is the value in fname?
String str;
int fname;
str = "Foolish boy.";
fname = str.indexOf("fool");
Correct
12. What is the value of ‘number’ after the following code fragment execution?
int number = 0;
int number2 = 12
while (number < number2)
{
number = number + 1;
}
You answered: 21
Incorrect
13. Given the following code snippet;
int salaries[];
int index = 0;
salaries = new int salaries[4];
while (index < 4)
{
salaries[index] = 10000;
index++;
}
What is the value of salaries [3]?
You answered: 50000
Incorrect
17. Assume that the value 3929.92 is of type ‘float’. How to assign this value after declaring the variable
‘interest’ of type float?
You answered: interest = (Float)3929.92
Incorrect
20. Which of the following statements declare class Sample to belong to the payroll.admindept package?
Correct
23. All the wrapper classes (Integer, Boolean, Float, Short, Long, Double and Character) in java
You answered: are immutatable
Incorrect
25. Consider the following code snippet. What will be assigned to the variable fourthChar, if the code is
executed?
26. Which of the following statements is preferred to create a string "Welcome to Java Programming"?
You answered: String str; str = new String (“Welcome to Java Programming” )
Incorrect
29. When a thread terminates its processing, into what state that thread enters?
You answered: Beginning state
Incorrect
34. Which of the methods should be implemented if any class implements the Runnable interface?
You answered: wait()
Incorrect
35. A thread which has invoked wait() method of an object, still owns the lock of the object. Is this
statement true or false?
Correct