Sail E0 Webinar

MCQs

Total Questions : 31 | Page 2 of 4 pages
Question 11. Determine output of the following program.
public class Test{
public static void main(String args[]){
System.out.println( Math.floor( Math.random( ) ) ) ;
}
}
  1.    1.0
  2.    10.0
  3.    0.0
  4.    0.5
 Discuss Question
Answer: Option C. -> 0.0
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.    Method 1
  2.    Method 2
  3.    Compile time error as final method can't be overloaded
  4.    None of the above
 Discuss Question
Answer: Option A. -> Method 1
Question 13. 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 the above
 Discuss Question
Answer: Option C. -> Compile time error
Question 14. 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.    The sum of x and y is 45
  3.    does not compile
  4.    None of the above
 Discuss Question
Answer: Option C. -> does not compile
Question 15. The implicit return type of a constructor is
  1.    void
  2.    A class object in which it is defined.
  3.    There is no return type.
  4.    None of the above
 Discuss Question
Answer: Option B. -> A class object in which it is defined.
Question 16. The finalize() method is called just prior to
  1.    An object, variable or method goes out of scope.
  2.    An object or variable goes out of scope.
  3.    A variable goes out of scope.
  4.    Before garbage collection.
  5.    None of the above
 Discuss Question
Answer: Option D. -> Before garbage collection.
Question 17. The main method should be static for the reason
  1.    It can be accessed easily by the class loader.
  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.    None of the above
 Discuss Question
Answer: Option C. -> It can be executed without creating any instance of the class.
Question 18. 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 2
  2.    2 and 4
  3.    3 and 4
  4.    1 and 3
 Discuss Question
Answer: Option B. -> 2 and 4
Question 19. 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 0
  3.    0 0
  4.    5 8
 Discuss Question
Answer: Option A. -> 0 8
Question 20. Public class Test { }
What is the prototype of the default constructor?
  1.    public Test(void)
  2.    Test( )
  3.    Test(void)
  4.    public Test( )
  5.    None of these
 Discuss Question
Answer: Option D. -> public Test( )

Latest Videos

Latest Test Papers