Sail E0 Webinar

MCQs

Total Questions : 31 | Page 1 of 4 pages
Question 1. What is the expected output?
public class Profile {
private Profile(int w) { // line 1
System.out.print(w);
}
public static Profile() { // line 5
System.out.print (10);
}
public static void main(String args[]) {
Profile obj = new Profile(50);
}
}
  1.    Won't compile because of line (1), constructor can't be private
  2.    10 50
  3.    50
  4.    Won't compile because of line (5), constructor can't be static
 Discuss Question
Answer: Option D. -> Won't compile because of line (5), constructor can't be static
Question 2. The following code contains one compilation error, find it?
public class Test {
Test() { } // line 1
static void Test() { this(); } // line 2
public static void main(String[] args) { // line 3
Test(); // line 4
}
}
  1.    At line 1, constructor Tester must be marked public like its class
  2.    At line 2, constructor call
  3.    At line 3, compilation error, ambiguity problem, compiler can't determine whether a constructor
  4.    At line 4
 Discuss Question
Answer: Option B. -> At line 2, constructor call
Question 3. What will be the return type of a method that not returns any value?
  1.    void
  2.    int
  3.    double
  4.    None of the above
 Discuss Question
Answer: Option A. -> void
Question 4. Which of the following options is the best for generating random integer 0 or 1?
  1.    (int)Math.random()
  2.    (int)Math.random() + 1
  3.    (int)(Math.random() + 0.5)
  4.    (int)(Math.random() + 0.2)
 Discuss Question
Answer: Option C. -> (int)(Math.random() + 0.5)
Question 5. What is Math.floor(3.6)?
  1.    3.0
  2.    3
  3.    4
  4.    4.0
 Discuss Question
Answer: Option B. -> 3
Question 6. In which area of memory, the system stores parameters and local variables whenever a method is invoked?
  1.    Heap
  2.    Storage Area
  3.    Stack
  4.    Array
 Discuss Question
Answer: Option C. -> Stack
Question 7. What is the expected output?
public class Profile {
private Profile(int w) { // line 1
System.out.print(w);
}
public final Profile() { // line 5
System.out.print(10);
}
public static void main(String args[]) {
Profile obj = new Profile(50);
}
}
  1.    Won't compile because of line (1); constructor can't be private
  2.    Won't compile because of line (5); constructor can't be final
  3.    50
  4.    10 50
 Discuss Question
Answer: Option B. -> Won't compile because of line (5); constructor can't be final
Question 8. What is the expected output?
class Animal {
Animal() {
System.out.println("Animal");
}
}
class Wild extends Animal{
Wild() {
System.out.println("Wild");
super();
}
}
public class Test {
public static void main(String args[]) {
Wild wild = new Wild();
}
}
  1.    Animal Wild
  2.    Wild Animal
  3.    Runtime Exception
  4.    Compilation Error
 Discuss Question
Answer: Option D. -> Compilation Error
Question 9. Which of the modifier can't be used for constructors?
  1.    public
  2.    private
  3.    static
  4.    protected
 Discuss Question
Answer: Option C. -> static
Question 10. The variables declared in a class for the use of all methods of the class are called
  1.    reference variables
  2.    objects
  3.    instance variables
  4.    None of these
 Discuss Question
Answer: Option C. -> instance variables

Latest Videos

Latest Test Papers