Oop1 Test

20 Questions | Total Attempts: 46

SettingsSettingsSettings
Please wait...
Programming Quizzes & Trivia

Questions and Answers
  • 1. 
    An abstraction denotes essential properties and behaviors of an object that differentiate from others.
    • A. 

      True

    • B. 

      False

  • 2. 
    Default value for a member float variable is:
    • A. 

      0.0

    • B. 

      0.0f

    • C. 

      0

    • D. 

      Garbage.

  • 3. 
    On which comment line of the program, constructor is located? (Choose One) public class Trial {        int c, s;                                            //1          public Trial(int start, int st){                //2        initialize(start);        initial(st);        }          public int get(){ return c; }                 //3          public void initialize(int v) { c = v; }    //4          public void initial(int sv) { s = sv; }     //5          public static void main(String[] args) {               int size = 20;               int[] arr = new int[size];                 for(int i = 0 ; i < size ; i++) {                      System.out.println(arr[i]);               }        } }
    • A. 

      Comment line 1.

    • B. 

      Comment line 2.

    • C. 

      Comment line 3.

    • D. 

      Comment line 4.

  • 4. 
    • A. 

      One object created.

    • B. 

      Two objects created.

    • C. 

      Three objects created.

    • D. 

      One reference variable is created.

    • E. 

      Two reference variables created.

    • F. 

      Three reference variables created.

  • 5. 
    An object is a blueprint for abstraction.
    • A. 

      True

    • B. 

      False

  • 6. 
    A class models abstraction by defining the properties and behaviors for objects represented by abstraction.
    • A. 

      True

    • B. 

      False

  • 7. 
    A static variable can be declared inside a method.
    • A. 

      True

    • B. 

      False

  • 8. 
    An instance member is: (Choose One)
    • A. 

      Is also called a static member.

    • B. 

      Is always a variable.

    • C. 

      Is never a method.

    • D. 

      Belongs to a single instance, not to the class as a whole.

    • E. 

      Always represents an operation.

  • 9. 
    How do objects pass messages in Java? (Choose One)
    • A. 

      By modifying each other’s variables.

    • B. 

      By modifying static member variables of each other’s classes.

    • C. 

      By calling each other’s instance member methods.

    • D. 

      By calling each other’s static member methods.

  • 10. 
    Given the following code, which statements are true? (Choose all valid answers) class X {        int value1; }   class Y extends X{        int value2; }
    • A. 

      Class X extends Y

    • B. 

      Class Y is superclass of X

    • C. 

      Class Y is subclass of X

    • D. 

      Objects of class X will contain variable value2.

  • 11. 
    Given the following code, what is true about it? (Choose One) import java.io.*; package P; public class X { private Other object; } public class Other { private int val; }
    • A. 

      X HAS A Other;

    • B. 

      The code doesn’t compile, because package statement is second statement.

    • C. 

      Import statement can never be first statement in a program file.

  • 12. 
    Which statements of the following are true? (Choose all that apply)
    • A. 

      In Java, the extends clause is used to specify inheritance.

    • B. 

      The subclass of a non-abstract class can be declared abstract.

    • C. 

      All the members of the superclass are inherited by the subclass.

    • D. 

      A final class can be abstract.

    • E. 

      A class, in which all the members are declared private, cannot be declared public.

  • 13. 
    Which of the following statements are true? (Choose Two)
    • A. 

      Inheritance defines a has-a relationship between a superclass and its subclasses.

    • B. 

      Every Java object has a method named equals().

    • C. 

      Every Java object has a method named length().

    • D. 

      A class can extend any number of other classes.

    • E. 

      A non-final class can be extended by any number of classes.

  • 14. 
    Which of the following statements are true? (Choose Two)
    • A. 

      Subclasses must define all methods that the superclass defines.

    • B. 

      It is possible for a subclass to define a method with same name and parameters as a method that superclass defines.

    • C. 

      A subclass cannot access the private members of superclass without using public members of parent class.

    • D. 

      It is possible for two classes to be superclass of each other.

  • 15. 
    Given following classes and declarations, which of the statements are true? (Choose all that apply) public class Super {        private int i;          public void fly(){  }        public void gravity(){  } }   class Sub extends Super {        public int j;        public void gravity() {   } }   //declarations          Super s = new Super();        Sub sb = new Sub();
    • A. 

      The Sub class is a legal subclass of Super.

    • B. 

      The statement sb.fly() is legal.

    • C. 

      The statement s.j = 5; is legal.

    • D. 

      The statement s.gravity(); is legal.

    • E. 

      The statement sb.i = 3 ; is legal.

  • 16. 
    Which of the following statements are true? (Choose One)
    • A. 

      Private methods cannot be overridden in subclasses.

    • B. 

      A subclass can override any method in a non-final superclass.

    • C. 

      The parameter list of an overriding method must be a subset of the parameter list of the method that it is overriding.

    • D. 

      The overriding method can have a different return value than the overridden method.

  • 17. 
    Given classes A, B and C, where B extends A and C extends B and where all classes implement the instance method void doIt(). How can the doIt() method in A be called from an instance method in C? (Choose One)
    • A. 

      DoIt();

    • B. 

      Super.doIt();

    • C. 

      ((A) this).doIt();

    • D. 

      It is not possible.

  • 18. 
    What would be the result of attempting to compile and run following code? (Choose One)   public class MyClass {        public static void main(String[] args) {               C c = new C();               System.out.println(c.max(13,29));        } }   class A {        int max(int x, int y) { if(x > y) return x; else return y; } }   class B extends A{        int max(int x, int y) { return super.max(y,x) – 10 ; } }   class C extends B {        int max(int x, int y) { return super.max(x+10, y+10) ; } }
    • A. 

      The code will fail to compile, since the max() method in B passes the arguments to the calling method in the wrong order.

    • B. 

      The code will fail to compile, owing to a call to a max() method being ambiguous.

    • C. 

      The code will compile and will print 13 when run.

    • D. 

      The code will compile and will print 23 when run.

    • E. 

      The code will compile and will print 29 when run.

    • F. 

      The code will compile and will print 39 when run.

  • 19. 
    Even when an object is not initialized, a static variable can be accessed
    • A. 

      True

    • B. 

      False

  • 20. 
    A static variable is common to all objects of the class.
    • A. 

      True

    • B. 

      False