0% found this document useful (0 votes)
263 views15 pages

Ques 1

The document contains 20 multiple choice questions about Java programming concepts such as main method signatures, return types, access modifiers, keywords, data types, arrays, and more. The questions test fundamental Java knowledge including syntax, semantics, and classes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
263 views15 pages

Ques 1

The document contains 20 multiple choice questions about Java programming concepts such as main method signatures, return types, access modifiers, keywords, data types, arrays, and more. The questions test fundamental Java knowledge including syntax, semantics, and classes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 15

Ques 1 : Which declaration of the main method below would allow a class to

be started as a standalone program.


(A) public static int main(char args[])
(B) public static void main(String args[])
(C) public static void MAIN(String args[])
(D) public static void main(String args)

Ques 2 : What is the meaning of the return data type void?


(A) An empty memory space is returned so that the developers can utilize it.
(B) void is not supported in Java
(C) void returns no data type.
(D) null

Ques 3 : Which of these are legal identifiers.


(A) number_1
(B) number_a
(C) $1234
(D) All of the above.

Ques 4 : Which of the following are Java keywords?


(A) throw
(B) void
(C) private
(D) All of the above.

Ques 5 : 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.
(A) True
(B) False

Ques 6 : Which of these are not legal identifiers.


(A) 1alpha
(B) xy+abc
(C) both A and B
(D) None of the above

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[])

(D) 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 9 : Which of the following are keywords in Java.


(A) implement
(B) friend
(C) NULL
(D) synchronized

Ques 10 : Which of these are legal array declarations or definitions?


(A) int[] []x[];
(B) int x[5];
(C) int *x;
(D) None of 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 12 : Which of the following statements is false about objects?

(A) An instance of a class is an object


(B) Objects can access both static and instance data
(C) Objects do not permit encapsulation
(D) Object is the super class of all other classes

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 14 : The class Hashtable is used to implement which collection


interface. Select the one correct answer.
(A) List
(B) Set
(C) Map
(D) SortedSet

Ques 15 : TreeMap class is used to implement which collection interface.


Select the one correct answer.
(A) Set
(B) SortedSet
(C) Tree
(D) SortedMap

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.

for(int i = 1; i < 3; i++)


for(int j = 3; j > i; j--)
assert i!=j {System.out.println(i); }
(A) The class compiles and runs, but does not print anything.
(B) The number 1 gets printed with AssertionError
(C) The program generates a compilation error.
(D) The number 2 gets printed with AssertionError

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

(A) The line labeled 1.


(B) The line labeled 2.
(C) The line labeled 3.
(D) All the lines are correct and the program compiles.

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 1 : Which methods can access to private attributes of a class?


(A) Only Static methods of the same class
(B) Only instances of the same class
(C) Only methods those defined in the same class
(D) Only classes available in the same package.

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 3 : Is the following statement true or false. The constructor of a class


must not have a return type.
(A) true
(B) false

Ques 4 : What is an aggregate object?

(A) An object with only primitive attributes


(B) An instance of a class which has only static methods
(C) An instance which has other objects
(D) None of the 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.

Ques 7 : Which of these are interfaces in the collection framework. Select


the two correct answers.
a.
Set
b.
List
c.
Array
d.
Vector
e.
LinkedList
(A) a,b,c
(B) a,b

(C) b,c,d,e
(D) c,d

Ques 8 : Which of the following are legal declaration and definition of a


method. Select all correct answers.
a.
void method() {};
b.
void method(void) {};
c.
method() {};
d.
method(void) {};
e.
void method {};
(A) a,b
(B) a
(C) a,b,c
(D) b,d,e

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 10 : Which of the assignment are not valid.


(A) short s = 28;
(B) float f = 2.3;
(C) double d = 2.3;
(D) int I = '1';

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.

(A) The number of bytes is compiler dependent.


(B) 2
(C) 4
(D) 8

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 16 : Which of these are interfaces in the collection framework. Select


the two correct answers.
a.
HashMap
b.
ArrayList
c.
Collection
d.
SortedMap
e.
TreeMap
(A) a,b
(B) c,d
(C) d,e
(D) a,d

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

Ques 2 : What is returned when the method substring(2, 4) is invoked on


the string "example"? Include the answer in quotes as the result is of type
String.
(A) "xa"

(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 7 : Which of the following statement is true about the assert


statement. Select the one correct answer.
(A) If a Java class contains assert statements, then it must be compiled with -1.4 option.
(B) When a program having assertions is run, -assertion option must be specified, otherwise the
assertions get ignored.
(C) A possible syntax of assert statement is assert logical_expression If logical_expression
evaluates to true, the program generates an AssertionError.
(D) The program terminates on its first AssertionError.

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 10 : Using up to four characters, write the Java representation of octal


literal 6.
(A) 06
(B) 006
(C) 0006
(D) all of above

Ques 11 : Using up to four characters what is the Java representation of the


number 23 in hex?
(A) 0x17
(B) 0x18
(C) 0x19
(D) 0x20

Ques 12 : What is the name of collection interface used to maintain unique


elements.
(A) List
(B) Set
(C) Map
(D) All of above

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 15 : Is this True or False. In Java an abstract class cannot be subclassed.


(A) True
(B) False

Ques 16 : What is the result of evaluating the expression 14 ^ 23. Select


the one correct answer.
(A) 23
(B) 24
(C) 25
(D) 26

Ques 17 : What are the two parts of a value of type double?


(A) Length, Denominator
(B) Significant Digits, Exponent
(C) Mode, Numerator
(D) Length, Numerator

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)

Ques 20 : What is the name of collection interface used to maintain


mappings of keys to values.
(A) List
(B) Set
(C) SortedSet
(D) Map

You might also like