Programming Language: JAVA

0



 MCQ on JAVA: A Programming Language

1. What will be the output of the following code snippet? 


if(true) System.out.print("A"); 

if(!false) System.out.print("B"); 

else if(true) System.out.print("C"); 

else System.out.print("D");


A. AB

B. AC

C. ABC

D. Compilation Error


2. Which of the following is INCORRECT header for the main method in java?

A. public final static void main(String[] arg)

B. static public void main(String arg [])

C. public static void main(String...arg)

D. None of These


3. Which of the following statement is TRUE about the following class? 

class A {}


A. It can be saved in a file named as B.java and compiled using command javac B.java 

B. It can be saved only with name A.java and compiled using command javac A.java 

C. It can not be instantiated.

D. None of These


4. All the objects in Java are created inside_________ and local variable in ______.

A. Class Area, Heap

B. Heap, Class Area

C. Heap, Stack

D. Class Area, Stack


5. What will be the output of the following code snippet?

int x=10, y=5;

 x = --y + x-- - --x + y;

System.out.println(x);


A. 10

B. 9

C. 11

D. 14


6. Which of the following keywords are NOT allowed with local variables in Java?

        i. private                    ii. static                    iii. final


A. only i

B. i & iii

C. i & ii

D. All


7. What will be the output of the following statement? 

int x=3, y=0;

System.out.println(++x>4 || y--> 0? ++y: --x);

A. 4

B. 3

C. 0

D. Compilation Error


8. What will be the output of the following code snippet? 

int x=-13, y=2; 

System.out.println(x>>y);

A. -3

B. -4

C. 3

D. Compilation Error


9. What will be the output of the following code? 

class Test

{

int x=10; 

Test(int a)

{

System.out.print(x++);

x=a;

}

public static void main(String [] arg)

{

new Test(5):

}

}

A. 0

B. 5

C. 10

D. Compilation Error


10. Which of the following keyword is NOT allowed with Constructor?

            i. final                 ii. static                 iii. private


A. ii & iii

B. i & ii

C. Only ii

D. i, ii & iii


11. What will be the output of the following Program? 

class A{

A(int x) { 

System.out.print("Hi "); 

               }

}

class B extends A{

B(int x) { 

System.out.print("Hello"); 

public static void main(String [] rk)

{

B b1= new B(1);

}

}

A. Hello

C. Hi Hello

B. Hi 

D. Compilation Error


12. What will be the output of the following code:

int i= 5, j=2; 

for(; i-->++j; ); 

System.out.println(i+""+j);


A. 43

B. 53

C. 34

D. Compilation Error


13. What will be the output of the following code snippet?

int i=10, j=5;

while(--i>10 && ++j>5); 

System.out.println(i+""+j);


A. 95

B. 105

C. 96

D. Compilation Error


14. Which of the following will print 7?

A. System.out.println(29 >> 2);

B. System.out.println(59 >>> 3);

C. byte b = -8; System.out.println(~b);

D. All the Above


15. What will the output of the following code snippet?


String [] str = new String[3];

str[1] = "A"; 

str[2] = "B";

str[3] = "C";                                    //Line 1

System.out.print(str);                     //Line 2     


A. Compilation Error in Line 1 

B. ABC

C. Compilation Error in Line 2

D. None of These


16. What will the output of the following code snippet?


first:    for(int i=0; i<3; i++)

{

second:     for(int j=i; j<3; j++)

{

if(j==2) break first;

if(i==j) continue second;

System.out.print(j);

}

}

A. 012

B. 01

C. 12

D. 1


17. What will the output of the following code snippet?


first:    for(int i=0; i<3; i++)

{

second:    for(int j=i; j<3; j++)

{

if(j==1) break first; 

if(i>j) continue second; 

System.out.print(j);

}

}

A. 0

B. 01

C. 12

D. 1


18. The correct output for the given below code

public class Task 

{

public static void main(String[] args) {

int x=5,y=1;

if(x++>5)

{

if(y<2)

System.out.println("Hi");

else

System.out.println("Bye");

}

else

System.out.println(x);

}

}

A. 6

B. Hi

C. Bye

D. 5


19. Output of the code 

public class Task

{

public static void main(String[] args) {

int x=5,y=1;

if(++x>5)

if(++y<2)

System.out.println("Hi");

else

System.out.println("Bye");

else

System.out.println("Hello");

}

}

A. Hi 

B. Bye 

C. Hello 

D. Blank Output


20. Which of the following is true about the following class?

public class A

{

public static void main(String[] args){}

}

A. It can be saved in a file named as B.java and compiled using command javac B.java 

B. It can be saved ONLY with name A.java and compiled using command javac A.java

C. Above class can not be compiled successfully. 

D. None of These






Tags

Post a Comment

0 Comments

Reply with suitable and helpful comment

Post a Comment (0)
To Top