Sail E0 Webinar

MCQs

Total Questions : 20 | Page 1 of 2 pages
Question 1. Given the following piece of code:public class School{ public abstract double numberOfStudent();}which of the following statements is true?
  1.    The keywords public and abstract cannot be used together.
  2.    The method numberOfStudent() in class School must have a body.
  3.    Class School must be defined abstract.
  4.    You must add a return statement in method numberOfStudent().
 Discuss Question
Answer: Option C. -> Class School must be defined abstract.
Question 2. Which of the following declares an abstract method in an abstract Java class?
  1.    public abstract method();
  2.    public void abstract Method();
  3.    public void method() {}
  4.    public abstract void method();
  5.    public abstract void method() {}
 Discuss Question
Answer: Option D. -> public abstract void method();
Question 3. Which of the following statements regarding abstract classes are true?
  1.    An abstract class can be extended.
  2.    All of these
  3.    An abstract class can be used as a data type.
  4.    A subclass of a non-abstract superclass can be abstract.
  5.    A subclass can override a concrete method in a superclass to declare it abstract.
 Discuss Question
Answer: Option B. -> All of these
Question 4. Suppose A is an abstract class, B is a concrete subclass of A, and both A and B have a default constructor. Which of the following is correct?1. A a = new A();2. A a = new B();3. B b = new A();4. B b = new B();
  1.    1 and 2
  2.    2 and 3
  3.    2 and 4
  4.    3 and 4
  5.    1 and 3
 Discuss Question
Answer: Option C. -> 2 and 4
Question 5. Which of the following class definitions defines a legal abstract class?
  1.    class A { abstract void unfinished(); }
  2.    abstract class A { abstract void unfinished(); }
  3.    public class abstract A { abstract void unfinished(); }
  4.    class A { abstract void unfinished() { } }
 Discuss Question
Answer: Option B. -> abstract class A { abstract void unfinished(); }
Question 6. Which of the following is a correct interface?
  1.    abstract interface A { print(); }
  2.    abstract interface A { abstract void print(); { }}
  3.    interface A { void print(); }
  4.    interface A { void print() { } }
 Discuss Question
Answer: Option C. -> interface A { void print(); }
Question 7. Given the following piece of code:public interface Guard{ void doYourJob();}abstract public class Dog implements Guard{ }which of the following statements is correct?
  1.    This code will not compile, because in the declaration of class Dog we must use the keyword extends instead of implements.
  2.    This code will compile without any errors.
  3.    This code will not compile, because class Dog must implement method doYourJob() from interface Guard.
  4.    This code will not compile, because method doYourJob() in interface Guard must be defined abstract.
 Discuss Question
Answer: Option B. -> This code will compile without any errors.
Question 8. What will be the output?interface A{public void method();}class One{public void method(){System.out.println("Class One method");}}class Two extends One implements A{public void method(){System.out.println("Class Two method");}}public class Test extends Two{public static void main(String[] args){A a = new Two();a.method();}}
  1.    will print Class One method
  2.    compiles fine but print nothing
  3.    None of these
  4.    will print Class Two method
  5.    Compilation Error
 Discuss Question
Answer: Option D. -> will print Class Two method
Question 9. In Java, declaring a class abstract is useful
  1.    When it makes sense to have objects of that class.
  2.    When it doesn't make sense to have objects of that class.
  3.    When default implementations of some methods are not desirable.
  4.    To force developers to extend the class not to use its capabilities.
  5.    To prevent developers from further extending the class.
 Discuss Question
Answer: Option B. -> When it doesn't make sense to have objects of that class.
Question 10. Determine output of the following code.interface A { }class C { }class D extends C { }class B extends D implements A { }public class Test extends Thread{ public static void main(String[] args){ B b = new B(); if (b instanceof A) System.out.println("b is an instance of A"); if (b instanceof C) System.out.println("b is an instance of C"); }}
  1.    Nothing.
  2.    b is an instance of
  3.    b is an instance of
  4.    b is an instance of A followed by b is an instance of
 Discuss Question
Answer: Option D. -> b is an instance of A followed by b is an instance of

Latest Videos

Latest Test Papers