Labels

Tuesday, August 12, 2014

Java Quiz 1

Q1- 
1. class Ex1{
2.   public static void main(String[] args) {
3.      int a[][] = new int[3][];
4.       a[1] = new int[]{1,2,3};
5.       a[2] = new int[]{4,5};
6.    System.out.print(a[1][1]);
7.    }
8.  }
 
Which is the output?

A. Compilation fails due to line 3.
B. Compilation fails due to line 4.
C. An exception will be thrown in runtime.
D. 2
E. 3
F. 5
 Ans 
Q2.
 
Choose the three legal identifiers.
A. 1stName
B. _4_
C. @name
D. $
E. getSize
 Ans:
Q3.


Given
1. class S{ 
2. public static void main(String [] args){ 
3. String s = "Java"; 
4. s.concat(" SE 6"); 
5. s.replace('6','7'); 
6. System.out.print(s); 
7. } 
8. }
What is the result?

A. Java SE 6
B. Java SE 7
C. Java SE
D. Java
E. Compilation fails.
  Ans 
Q4.
In the following pieces of code, A and D will compile without any error. True or false?
A: StringBuffer sb1 = "abcd";
B: Boolean b = new Boolean("abcd");
C: byte b = 255;
D: int x = 0x1234;
E: float fl = 1.2;
True
False
 Ans 
 

No comments:

Post a Comment