Sei sulla pagina 1di 9

Question 1

Given file is a File object, which of the following is legal statement to create
a new file
Select one:
a. file.create();
b. FileOutputStream fos = new FileOutputStream(file);
c. FileInputStream fis = new FileInputStream(file);
d. all of the above
ANS:
Question 2
A member method of a class can always access the data
Select one:
a. in the object of which it is a member
b. in the class of which it is a member
c. in any object of the class of which it is a member
d. in public methods
ANS:
Question 3
All the bitwise operators have the same level of precedence in Java.
Select one:
a. True
b. False
ANS:
Question 4
Which is the valid way to create DataInputStream streams?
Select one:
a. new DataInputStream("in.dat", "r");
b. new DataInputStream("in.dat")
c. new DataInputStream(new File("in.dat"));
d. new DatalnputStream(new FileInputStream("in.dat");
ANS:
Question 5
Which of the following statements are true? <br>1. We cannot use abstract classe
s to instantiate objects directly. <br>2. The abstract methods of an abstract cl
ass must be defined in its subclass. <br>3. We cannot declare abstract construct
ors. <br>4. We may declare
Select one:
a. Line 1 only
b. Line 2 only
c. Line 1 and line 2 only
d. Line 1, line 2 and line 3 only
ANS:
Question 6
Which of the following is not a keyword?
Select one:
a. implements
b. protected

c. extended
d. All of these are keywords
ANS:
Question 7
Question text
The concept of multiple inheritance is implemented in Java by
Select one:
a. extending two or more classes
b. extending one class and implementing one or more interfaces
c. all the above
d. none of the above
ANS:
Question 8
When we implement the Runnable interface, we must define the method
Select one:
a. start()
b. init()
c. run()
d. runnable()
ANS:
Question 9
Which of the following is not correct?
Select one:
a. int a = 16, a >> 2 = 4
b. int b = -8, b >> 1 = - 4
c. int a = 16, a >>> 2 = 4
d. int b = -8, b >>> 1 = - 4
ANS:
Question 10
Any method in a super class can be overridden in its subclass.
Select one:
a. True
b. False
ANS:
Question 11
Consider the following statements: <br>int x = 10, y = 15; <br>x = ((x<y) ? (y+x
) : (y-x)); <br>What will be the value of x after executing these statements?
Select one:
a. 10
b. 25
c. 15
d. Error. Cannot be executed.
ANS:
Question 12
Consider the following code: <br>int number[] = new int[5]; <br>After execution
of this statement, which of the following is true?
Select one:
a. number[] is undefined

b. number[5] is undefined
c. number[4] is null
d. All
ANS:
Question 13
A good reason to use an object-oriented language is that
Select one:
a. you can define various data types
b. program statements are simpler than in procedural languages
c. it is easier to conceptualize an object-oriented program and reuse the code
d. an object-oriented program can correct its own mistakes
ANS:
Question 14
It is an error, if a class with one or more abstract methods is not explicitly d
eclared abstract.
Select one:
a. True
b. False
ANS:
Question 15
Which of the following are illegal loop constructs?
Select one:
a. for(int i = 10, int j = 0; i+j > 5; i = i-2, j++) <br>{<br>Body statements <b
r>}
b. int i = 10; <br>while(i) <br>{<br>Body statements <br>}
c. int i = 1, sum = 0; <br>do {loop statements} <br>while(sum<10 || i<5);
d. None of the above
ANS:
Question 16
A variable declared inside the for loop control cannot be referenced outside the
loop.
Select one:
a. True
b. False
ANS:
Question 17
Which of the following will produce a value of 10 if x = 9.7 ?
Select one:
a. floor(x)
b. abs(x)
c. rint(x)
d. round(x)
ANS:
Question 18
Which of the following is the most appropriate statement?
Select one:

a.
b.
c.
d.

all
the
all
all

variables must be declared before they are used in Java


data type of variables is assigned dynamically in Java
variables can be declared at the end of the Java program
of the above

ANS:
Question 19
The range of values for the long type data is
Select one:
a. -231 to 231 - 1
b. -264 to 264
c. -263 to 263 - 1
d. -232 to 232 - 1
ANS:
Question 20
Throwing an Exception always causes program termination.
Select one:
a. True
b. False
ANS:
Question 21
A thread wants to make a second thread ineligible for execution. To achieve this
, the first thread can call the yield( ) method on the second thread.
Select one:
a. True
b. False
ANS:
Question 22
Which of the following methods belong to the String class?
Select one:
a. length()
b. compareTo()
c. equals()
d. All of them
ANS:
Question 23
We can overload methods with differences only in their return type.
Select one:
a. True
b. False
ANS:
Question 24
What is the error in the following code? <br>class Test <br>{<br>abstract void d
isplay( ); <br>}
Select one:
a. No error
b. Method display() should be declared as static
c. Test class should be declared as abstract
d. Test class should be declared as public

ANS:
Question 25
Two methods cannot have the same name in Java.
Select one:
a. True
b. False
ANS:
Question 26
Which of the following thread state transition is valid?
Select one:
a. ready to waiting
b. ready to running
c. waiting to running
d. all of the above
ANS:
Question 27
The break statement is required in the default case of a switch selection struct
ure.
Select one:
a. True
b. False
ANS:
Question 28
A catch can have comma-separated multiple arguments.
Select one:
a. True
b. False
ANS:
Question 29
Consider the following class definition: <br>class A extends B <br>{<br>public A
(int x) { } <br>public A(int x, int y) <br>{<br>super (x, y); <br>} <br>}<br>Whi
ch of the following is legal statement to construct A type objects?
Select one:
a. A a = new A();
b. A a = new A(4, 2, 7);
c. A a = new A(5, 6);
d. A a = new A(Base(4, 5), 6);
ANS:
Question 30
Correct
Mark 1.00 out of 1.00
Which of the following statement is true?
Select one:

a.
b.
c.
d.

A Java monitor must either extend Thread or implement Runnable.


The sleep() method should be enclosed in try .... catch block.
The yield() method should be enclosed in try .... catch block.
All of them

ANS:
Question 31
Which of the following expression is illegal?
Select one:
a. (10 | 5)
b. (false && true)
c. boolean x = (boolean)10;
d. int x = 10;
ANS:
Question 32
Consider the following code: <br>char c = 'a'; <br>switch(c) <br>{<br>case 'a':
<br>System.out.println("A"); <br>case 'b': <br>System.out.println("B"); <br>defa
ult: <br>System.out.println("C"); <br>} <br>For this code, which of the followin
g statement is true?
Select one:
a. output will be A
b. output will be A followed by B
c. output will be A, followed by B, and then followed by C
d. code is illegal and therefore will not compile
ANS:
Question 33
Which of the following statement is true?
Select one:
a. Unicode characters are all 16 bits.
b. UTF characters are all 24 bits.
c. Reader class has methods that can read integers and floats.
d. all of the above
ANS:
Question 34
The programmer must explicitly create the System.in and System.out objects.
Select one:
a. True
b. False
ANS:
Question 35
One of the features of Java is that an array can store many different types of v
alues
Select one:
a. True
b. False
ANS:
Question 36
Which of the following assignment is valid?
Select one:

a.
b.
c.
d.

float x = 123.4;
long m = 023;
int n = (int) false;
All

ANS:
Question 37
A String object cannot be modified after it is created.
Select one:
a. True
b. False
ANS:
Question 38
Consider the following class definition. <br>class Student extends String <br>{<
br>} <br>What happens when we try to compile this class?
Select one:
a. Will not compile because class body is not defined
b. Will not compile because the class is not declared public
c. Will not compile because String is abstract
d. Will not compile because String is final
ANS:
Question 39
Every method of a final class is implicitly final.
Select one:
a. True
b. False
ANS:
Question 40
Select the correct statement out of the following:
Select one:
a. Void class extends the class Class
b. Float class extends the class Double
c. System class extends the class Runtime
d. Integer class extends the class Number
ANS:
Question 41
Given the code <br>String s = new String("abc"); <br>Which of the following call
is valid?
Select one:
a. s.toUpperCase()
b. s.setCharAt(l, 'A')
c. s.append("xyz")
d. All of them
ANS:
Question 42
DataInput is
Select one:
a. an abstract class defined in java.io.
b. a class we can use to read primitive data types.

c. an interface that defines methods to open files.


d. an interface that defines methods to read primitive data types.
ANS:
Question 43
Consider the following code: <br>interface Area <br>{<br>float compute(float x,
float y); <br>} <br>class Room implements Area <br>{<br>float compute(float x, f
loat y) <br>{<br>return (x * y); <br>}<br>} <br>What is wrong with the code?
Select one:
a. Interface definition is incomplete
b. Method compute() in interface Area should be declared public
c. Method compute() in class Room should be declared public
d. All the above
ANS:
Question 44
Consider the following code <br>if (number >= 0) <br>if (number > 0) <br>System.
out.println("Number is positive"); <br>else <br>System.out.println("Number is ne
gative"); <br>What will be the output if number is equal to 0?
Select one:
a. Number is negative
b. Number is positive
c. Both of the above
d. None of the above
ANS:
Question 45
When we implement an interface method, it should be declared as public.
Select one:
a. True
b. False
ANS:
Question 46
Which of the following keyword is used to control access to a class member?
Select one:
a. default
b. abstract
c. interface
d. none
ANS:
Question 47
Which of the following control expressions are valid for an if statement?
Select one:
a. an integer expression
b. a boolean expression
c. Both of the above
d. None of the above
ANS:
Question 48
Sharing of common information is achieved by the concept of
Select one:

a.
b.
c.
d.

polymorphism
inheritance
encapsulation
none of these

ANS:
Question 49
Given the declarations <br>int x, m = 2000; <br>short y; <br>byte b1 = -40, b2;
<br>long n; <br>Which of the following assignment statement will evaluate correc
tly?
Select one:
a. x = m * b1;
b. y = m * b1;
c. x = m * 3L;
d. all of the above
ANS:
Question 50
The output of the following program when it is invoked using the command line is
: <br>java Test this is a test?<br>class Test <br>{<br>public static void main{S
tring s[]) <br>{<br>System.out.println(s[0]); <br>}<br>}
Select one:
a. this
b. is
c. this is a test?
d. none of these

Potrebbero piacerti anche