Sail E0 Webinar

MCQs

Total Questions : 26 | Page 2 of 3 pages
Question 11. What is the output of the following program?public class Test{static int x = 10 ; public static void main(String[] a){ Test test = new Test( ) ; Test test1 = new Test( ) ; test.x += 1 ; System.out.println( test.x + test1.x ) ; }}
  1.    Throws Exception
  2.    Compilation Error
  3.    20
  4.    22
  5.    21
 Discuss Question
Answer: Option D. -> 22
Question 12. What will be output of the following program code?public class Test{public static void main(String[] a){short x = 10;x = x*5;System.out.print(x);} }
  1.    50
  2.    None of these
  3.    10
  4.    Compilation Error
 Discuss Question
Answer: Option D. -> Compilation Error
Question 13. The following fraction of codedouble STATIC = 2.5 ;System.out.println( STATIC );
  1.    Raises an exception
  2.    Prints 2.5
  3.    None of these
  4.    Rraises an error as STATIC is used as a variable which is a keyword
 Discuss Question
Answer: Option B. -> Prints 2.5
Question 14. What would be the output of the following fraction of code ?int Integer = 34 ;char String = 'S' ;System.out.print( Integer ) ;System.out.print( String ) ;
  1.    Does not compile as Integer and String are API class names.
  2.    S
  3.    34 S
  4.    Throws exception.
  5.    34
 Discuss Question
Answer: Option C. -> 34 S
Question 15. Determine output:public class Test{int i = 34;public static void main(String args[]){Test t1 = new Test();Test t2 = new Test();t1.i = 65;System.out.print(t1.i);System.out.print(t2.i);}}
  1.    34 34
  2.    34 65
  3.    65 34
  4.    65 65
 Discuss Question
Answer: Option C. -> 65 34
Question 16. The following program:public class Test{ static boolean isOK; public static void main(String args[]){ System.out.print(isOK); } }
  1.    Prints true
  2.    Prints false
  3.    Will not compile as boolean is not initialized
  4.    Will not compile as boolean can never be static
 Discuss Question
Answer: Option B. -> Prints false
Question 17. What is the output for the below code?public class Test{ int _$; int $7; int do; public static void main(String argv[]){ Test test = new Test(); test.$7=7; test.do=9; System.out.println(test.$7); System.out.println(test.do); System.out.println(test._$); }}
  1.    Compile error - $7 is not valid identifier.
  2.    7 9 0
  3.    Compile error - do is not valid identifier.
  4.    None of these
  5.    7 0 0
 Discuss Question
Answer: Option C. -> Compile error - do is not valid identifier.
Question 18. What is the output for the below code ?class A{ int k; boolean istrue; static int p; public void printValue(){ System.out.print(k); System.out.print(istrue); System.out.print(p); }}public class Test{ public static void main(String argv[]){ A a = new A(); a.printValue(); }}
  1.    Compile error - static variable must be initialized before use.
  2.    0 false 0
  3.    0 true 0
  4.    0 0 0
  5.    None of these
 Discuss Question
Answer: Option B. -> 0 false 0
Question 19. What will the output of the following program?public class Test{ public static void main(String args[]){ float f = (1 / 4) * 10; int i = Math.round(f); System.out.println(i); }}
  1.    3
  2.    2.5
  3.    25
  4.    2
  5.    0
 Discuss Question
Answer: Option E. -> 0
Question 20. In Java, the word true is ................
  1.    A Boolean literal
  2.    Same as value 1
  3.    A Java keyword
  4.    Same as value 0
 Discuss Question
Answer: Option A. -> A Boolean literal

Latest Videos

Latest Test Papers