Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

1.

Reason for Java language is platform independent


a) write anywhere, run once
b) write once, run anywhere
c) write once, run once
d) write twice run once

Answer: b

2. What are all the different primitive data types in java?


a) char, byte, short, int , long, float, double, boolean
b) char, byte, short, int , long, float, Boolean, complex
c) char, byte, short, int , long, float, double, String
d) char, byte, short, int , long, float, double, Boolean, String

Answer: a

3. What would be following syntax yields?

Public static void main(String[] args){


int x = 0786;

a) 786
b) Compile Time Error
c) Run Time Error
d) None of the above

Answer: b

4. What is the output of the following program?

public class Test {

public static void main(String[] args) {


String str1= new String("ABCD");
String str2= new String("ABCD");
if(str1 == str2)
{
System.out.println("Right");
}
}

}
a) Right
b) ABCD
c) Compile Time Error
d) Nothing will be Printed

Answer: d

5. What is the output of the following program?

public class Test {

public static void main(String[] args) {


String str1 = "ABCD";
String str2 = "ABCD";
String str3 = new String("ABCD");
String str4 = new String("ABCD");

if(str1 == str2)
{
System.out.println("Right");
}

if(str2==str3){
System.out.println("Left");
}

if(str3.equals(str4)){
System.out.println("Centre");
}

a) Right, Left
b) Left, Centre
c) Right, Centre
d) Right, Left, Centre

Answer: c
6. What is the correct way of declaring an array?
1) int[] x = new int[5];
2) int[] x = new int[‘a’];
3) int [] x = new int[-1];
4) int[] x = new int[32768]

a) 1,2,4
b) 1,2
c) 1,2,3
d) 1,4

Answer: b

7. equals( ) & hashcode( ) are part of which class in Java?

a) Exception class
b) Thread class
c) HashMap class
d) Object class

Answer: d

8. What are the flow control keywords in Java?

a) If, if-else, if-elseif-else, switch


b) If, if-else, if-elseif-else
c) If, if-else, if-elseif-else, switch, break
d) If, if-else, if-elseif-else, break, continue

Answer: c

9. What are the iteration related keywords in Java?

a) for, while, do-while


b) for, while, do-while, break, continue
c) for, while, do-while, continue
d) for, while, break, continue

Answer: b
10. What are the advantages of having wrapper classes in Java for primitive data types?

a) Easy Data Type Conversion


b) To have values in the form of objects
c) Another way to represent data
d) Better Coding

Answer: a

You might also like