Ques 1
Ques 1
Ques 7 : Which of the following are legal definitions of the main method that
can be used to execute a class.
(A) public static int main(String args[])
(B) public void main(String args)
(C) public static void main(String args[])
Ques 8 : Which of the following statements about the Java language is true?
(A) Both procedural and OOP are supported in Java.
(B) Java supports only procedural approach towards programming.
(C) Java supports only OOP approach.
(D) None of the above.
Ques 11 : What gets printed when the following code is compiled and run
with the following command - java test 2 Select the one correct answer.
public class test {
public static void main(String args[]) {
Integer intObj=Integer.valueOf(args[args.length-1]);
int i = intObj.intValue();
if(args.length > 1)
System.out.println(i);
if(args.length > 0)
System.out.println(i - 1);
else
System.out.println(i - 2);
}
}
(A) test
(B) test -1
(C) 0
(D) 1
Ques 13 : Which of these are legal identifiers. Select the three correct
answers.
a.
number_1
b.
number_a
c.
$1234
d.
-volatile
(A) a, b, c
(B) a, b
(C) a
(D) b
Ques 16 : Given a one dimensional array arr, what is the correct way of
getting the number of elements in arr. Select the one correct answer.
(A) arr.length
(B) arr.length - 1
(C) arr.size
(D) arr.length()
Ques 17 : What happens when the following code is compiled and run.
Select the one correct answer.
Ques 18 : What gets displayed on the screen when the following program is
compiled and run. Select the one correct answer.
protected class example {
public static void main(String args[]) {
String test = "abc";
test = test + test;
System.out.println(test);
}
}
(A) The class does not compile because the top level class cannot be protected.
(B) The program prints "abc"
(C) The program prints "abcabc"
(D) The program does not compile because statement "test = test + test" is illegal.
Ques 19 : In the following class definition, which is the first line (if any) that
causes a compilation error. Select the one correct answer.
public class test {
public static void
char c;
int i;
c = 'A';
i = c;
c = i + 1;
c++;
}
}
main(String args[]) {
// 1
//2
//3
//4
Ques 20 : Which of the following is a Java keyword. Select the four correct
answers.
a.
extern
b.
synchronized
c.
volatile
d.
friend
e.
friendly
f.
transient
g.
this
h.
then
(A) b, c
(B) b, c, f, g
(C) e, g, h
(D) all of above.
Ques 2 : Which of these are not legal identifiers. Select the four correct
answers.
a.
1alpha
b.
_abcd
c.
xy+abc
d.
transient
e.
account-num
f.
very_long_name
(A) a, c, e
(B) a, c, d, e
(C) c, d, e, f
(D) all of above
Ques 5 : Which of the following are keywords in Java. Select the two correct
answers.
a.
friend
b.
NULL
c.
implement
d.
synchronized
e.
throws
(A) d, e
(B) a, b
(C) a, b, c
(D) all of above
Ques 6 : What gets printed when the following program is compiled and
run? Select the one correct answer.
class test {
public static void main(String args[]) {
int i;
do {
i++;
}
while(i < 0);
System.out.println(i);
}
}
(A) The program does not compile as i is not initialized.
(B) The program compiles but does not run.
(C) The program compiles and runs but does not print anything.
(D) The program prints 0.
(C) b,c,d,e
(D) c,d
Ques 9 : What happens when the following code is compiled and run. Select
the one correct answer.
for(int i = 1; i < 3; i++)
for(int j = 3; j >= 1; j--)
assert i!=j : i;
(A) The class compiles and runs, but does not print anything.
(B) The number 1 gets printed with AssertionError
(C) The number 2 gets printed with AssertionError
(D) The number 3 gets printed with AssertionError
Ques 11 :
A top level class may have only the following access modifier. Select the one
correct answer.
(A) package
(B) protected
(C) private
(D) public
Ques 12 : What is the number of bytes used by Java primitive long. Select
the one correct answer.
Ques 13 : 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?
(A) Binary File
(B) Image File
(C) Both File and Binary Files
(D) None of the above
Ques 14 : Which of the following are Java keywords. Select the four correct
answers.
a.
super
b.
strictfp
c.
void
d.
synchronize
e.
instanceof
(A) a, b
(B) a, b, c, e.
(C) b, c, d
(D) a, c, d, e
Ques 15 : What gets printed when the following program is compiled and
run? Select the one correct answer.
class xyz {
static int i;
public static void main(String args[]) {
while (i < 0) {
i--;
}
System.out.println(i);
}
}
(A) The program does not compile as i is not initialized.
(B) The program compiles but does not run.
(C) The program compiles and runs but does not print anything.
(D) The program prints 0.
Ques 17 : What happens when the following code is compiled and run.
Select the one correct answer.
for(int i = 1; i < 4; i++)
for(int j = 1; j < 4; j++)
if(i < j)
assert i!=j : i;
(A) The class compiles and runs, but does not print anything.
(B) The number 1 gets printed with AssertionError
(C) The number 2 gets printed with AssertionError
(D) The number 3 gets printed with AssertionError
Ques 18 : What gets printed on the standard output when the class below is
compiled and executed. Select the one correct answer.
public class ShortCkt {
public static void main(String args[])
int i = 0;
boolean t = true;
boolean f = false, b;
b = (t || ((i++) == 0));
b = (f || ((i+=2) > 0));
System.out.println(i);
}
}
(A) 0
(B) 1
(C) 2
(D) 3
Ques 19 : What gets printed when the following program is compiled and
run. Select the one correct answer.
class test {
public static void main(String args[]) {
int i,j,k,l=0;
k = l++;
j = ++k;
i = j++;
System.out.println(i);
}
}
(A) 0
(B) 1
(C) 2
(D) 3
Ques 20 : Write down the modifier of a method that makes the method
available to all classes in the same package and to all the subclasses of this
class.
(A) public
(B) protected
(C) private
(D) default
Ques 1 : Which of these statements are legal. Select the three correct
answers.
a.
int arr[][] = new int[5][5];
b.
int []arr[] = new int[5][5];
c.
int[][] arr = new int[5][5];
d.
int[] arr = new int[5][];
e.
int[] arr = new int[][5];
(A) a, b
(B) a, b, c
(C) a, b, c, d
(D) a, b, c, d, e
(B) "am"
(C) "xm"
(D) "xamp"
Ques 3 : 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
(A) Method Invocating
(B) Method Overriding
(C) Method Labeling
(D) Method Overloading
Ques 4 : Which of these are Java keywords. Select the five correct answers
a.
TRUE
b.
volatile
c.
transient
d.
native
e.
interface
f.
then
g.
new
(A) b, d, f, g
(B) a, b, d, g
(C) b, c, d, e, g
(D) d, e, f, g
Ques 5 : What gets printed when the following program is compiled and
run? Select the one correct answer.
class xyz {
public static void main(String args[]) {
int i,j,k;
for (i = 0; i < 3; i++) {
for(j=1; j < 4; j++) {
for(k=2; k<5; k++) {
if((i == j) && (j==k))
System.out.println(i);
}
}
}
}
}
(A) 0
(B) 1
(C) 2
(D) 3
Ques 6 : What is the name of collection interface used to maintain nonunique elements in order.
(A) Set
(B) List
(C) Map
(D) SortedSet
Ques 8 : Which of the following is correct? Select the two correct answers.
a.
The native keyword indicates that the method is implemented in
another
language like C/C++.
b.
The only statements that can appear before an import statement in a
Java file are comments.
c.
The method definitions inside interfaces are public and abstract. They
cannot be private or protected.
d.
A class constructor may have public or protected keyword before
them,
nothing else.
(A) a, b
(B) a, c
(C) b, c
(D) c, d
Ques 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?
(A) Object
(B) Class
(C) Method
(D) Real data types
Ques 13 : Which of the following are valid constructors within a class Test.
Select the two correct answers.
a.
test() { }
b.
Test() { }
c.
void Test() { }
d.
private final Test() { }
e.
abstract Test() { }
f.
Test(Test t) { }
g.
Test(void) { }
(A) b, d
(B) c, f
(C) b, c
(D) b, f
Ques 14 : What gets printed on the standard output when the class below is
compiled and executed. Select the one correct answer.
public class ShortCkt {
public static void main(String args[]) {
int i = 0;
boolean t = true;
boolean f = false, b;
b = (t | ((i++) == 0));
b = (f | ((i+=2) > 0));
System.out.println(i);
}
}
(A) 0
(B) 1
(C) 2
(D) 3
Ques 18 : What is the minimum value of char type. Select the one correct
answer.
(A) 0
(B) -215
(C) -28
(D) -215 - 1
Ques 19 : What gets printed when the following program is compiled and
run? Select the one correct answer.
class test
{
static boolean check;
public static void main(String args[])
{
int i;
if(check == true)
i=1;
else
i=2;
if(i=2) i=i+2;
else i = i + 4;
System.out.println(i);
}
}
(A) 3
(B) 4
(C) 5
(D) The program does not compile because of the statement if(i=2)