Sail E0 Webinar

MCQs

Total Questions : 30 | Page 2 of 3 pages
Question 11. What is the output of the program?class Test{ public int display(int x, int y){ return ("The sum of x and y is " + x + y); } public static void main(String args[]){ Test test = new Test(); System.out.println(test.display(4,5)); } }
  1.    The sum of x and y is 9
  2.    None of these
  3.    The sum of x and y is 45
  4.    does not compile
 Discuss Question
Answer: Option D. -> does not compile
Question 12. Determine Output:class A{public static void method(int i){System.out.print("Method 1");}public static int method(String str){System.out.print("Method 2");return 0;}}public class Test{ public static void main(String args[]){A.method(5);}}
  1.    None of these
  2.    Method 1
  3.    Compile time error as final method can't be overloaded
  4.    Method 2
 Discuss Question
Answer: Option B. -> Method 1
Question 13. The implicit return type of a constructor is
  1.    There is no return type.
  2.    void
  3.    A class object in which it is defined.
  4.    None of these
 Discuss Question
Answer: Option C. -> A class object in which it is defined.
Question 14. Determine output of the following program.public class Test{ public static void main(String args[]){ System.out.println( Math.floor( Math.random( ) ) ) ; }}
  1.    10.0
  2.    0.5
  3.    1.0
  4.    0.0
 Discuss Question
Answer: Option D. -> 0.0
Question 15. What is the output of the above program ?class Num { Num(double x ){ System.out.println( x ) ; } }public class Test extends Num { public static void main(String[] args){ Num num = new Num( 2 ) ; } }
  1.    0
  2.    2.0
  3.    Compile time error
  4.    None of these
 Discuss Question
Answer: Option C. -> Compile time error
Question 16. Given the following piece of code:class Person{ public int number;}public class Test{ public void doIt(int i , Person p){ i = 5; p.number = 8; } public static void main(String args[]){ int x = 0; Person p = new Person(); new Test().doIt(x, p); System.out.println(x + " " + p.number); }}What is the result?
  1.    0 8
  2.    5 8
  3.    5 0
  4.    0 0
 Discuss Question
Answer: Option A. -> 0 8
Question 17. The finalize() method is called just prior to
  1.    A variable goes out of scope.
  2.    An object or variable goes out of scope.
  3.    None of these
  4.    An object, variable or method goes out of scope.
  5.    Before garbage collection.
 Discuss Question
Answer: Option E. -> Before garbage collection.
Question 18. The main method should be static for the reason
  1.    None of these
  2.    It can be accessed by every method or variable without any hindrance.
  3.    It can be executed without creating any instance of the class.
  4.    It can be accessed easily by the class loader.
 Discuss Question
Answer: Option C. -> It can be executed without creating any instance of the class.
Question 19. Public class Test { }What is the prototype of the default constructor?
  1.    Test(void)
  2.    None of these
  3.    Test( )
  4.    public Test( )
  5.    public Test(void)
 Discuss Question
Answer: Option D. -> public Test( )
Question 20. Which of the following statements regarding static methods are correct?1. Static methods are difficult to maintain, because you can not change their implementation.2. Static methods can be called using an object reference to an object of the class in which this method is defined.3. Static methods are always public, because they are defined at class-level.4. Static methods do not have direct access to non-static methods which are defined inside the same class.
  1.    1 and 3
  2.    3 and 4
  3.    1 and 2
  4.    2 and 4
 Discuss Question
Answer: Option D. -> 2 and 4

Latest Videos

Latest Test Papers