Java Oops Quiz

22 Questions | Total Attempts: 16767

SettingsSettingsSettings
Please wait...
Java Oops Quiz

Popularly known as Java's object-oriented programming concepts, Oops form the backbone of java programming. Tech specialists and programmers are familiar with this but giving the quiz a short will be worthwhile in advancing your knowledge. This "Java OOPs Quiz" is designed to test your understanding of the concepts of Java OOPs. Make sure to pick the right option to get the highest score! Good Luck!


Questions and Answers
  • 1. 
    HAS-A relationships are based on inheritance, rather than usage.  
    • A. 

      True

    • B. 

      False

  • 2. 
    Given below the sample code :   1   class Hotel { 2   public int bookings; 3   public void book() { 4   bookings++; 5   } 6   } 7   public class SuperHotel extends Hotel { 8   public void book() { 9   bookings--; 10  } 11  public void book(int size) { 12  book(); 13  super.book(); 14  bookings += size; 15  } 16  public static void main(String args[]) { 17  Hotel hotel = new Hotel(); 18  hotel.book(2); 19  System.out.print(hotel.bookings); 20  }}   How can we correct the above code ? (choose all that apply)  
    • A. 

      By adding argument "int size" to the method book at line number 3.

    • B. 

      By removing argument '2' at line number 18.

    • C. 

      By creating object of "SuperHotel" subclass at line 17 & calling book(2) from it at line 18

    • D. 

      No correction needed.

  • 3. 
     The methods in class object are(choose four)  
    • A. 

      Clone

    • B. 

      Notify

    • C. 

      Concat

    • D. 

      Wait

    • E. 

      Equals

    • F. 

      Compare

  • 4. 
      Array or collection of superclass references can be used to access a mixture of superclass and subclass objects.  
    • A. 

      True

    • B. 

      False

  • 5. 
    Given the following sample code:   public class Example5{       public float Twin(float a, float b) {...         } public float Twin(float a1, float b1) { ...}           }   How can we correct the above code ?(choose two)  
    • A. 

      By placing overriding method into subclass.

    • B. 

      By changing the name of the class.

    • C. 

      By replacing overloading from overriding.

    • D. 

      By changing the name of the arguments.

  • 6. 
    At run-time, a Java program is nothing more than objects ‘talking’ to ___________.
    • A. 

      Other objects

    • B. 

      Other metods

    • C. 

      Other classes

    • D. 

      Other binders

  • 7. 
       The relation between Car and Owner or BankAccount and Customer is example for  
    • A. 

      Aggregation

    • B. 

      Composition

    • C. 

      Association

    • D. 

      None

  • 8. 
    Aggregation is a special form of association.  
    • A. 

      True

    • B. 

      False

  • 9. 
     Subclassing polymorphism is sometimes called “true polymorphism”.
    • A. 

      True

    • B. 

      False

  • 10. 
    Consider the below code and choose the correct output. public class Main { public int a; public long b; public void test(long  b) { System.out.println("long b"); } public void test(int a) { System.out.println("int a"); } public static void main(String[] args) {                 Main e=new Main();         e.test(9*1000000000);               }   }  
    • A. 

      Int a

    • B. 

      Long b

    • C. 

      Long a

    • D. 

      Error

  • 11. 
      An interface cannot have an inner class.  
    • A. 

      True

    • B. 

      False

  • 12. 
    Polymorphism is one interface with __________.  
    • A. 

      Single method

    • B. 

      Multiple methods

    • C. 

      Multiple record

    • D. 

      Single record

  • 13. 
    Method overloading is done during _______.
    • A. 

      Runtime

    • B. 

      Dynamic binding

    • C. 

      Program compilation

    • D. 

      Late binding

  • 14. 
    Interfaces are fast as it requires extra indirection to find corresponding method in the actual class.  
    • A. 

      True

    • B. 

      False

  • 15. 
    Ad hoc polymorphism is ____________.
    • A. 

      Method Overloading

    • B. 

      Method Overriding

    • C. 

      Subclassing polymorphism

    • D. 

      Dynamic binding

  • 16. 
    The inheriting class cannot override the definition of existing methods by providing its own implementation.
    • A. 

      True

    • B. 

      False

  • 17. 
    Consider the code below and choose the correct option. class GameShape { public void displayShape() { System.out.println("displaying shape");    }    // more code }   class PlayerPiece extends GameShape { public void movePiece() { System.out.println("moving game piece");    }    // more code }   public class TestShapes {    public static void main (String[] args) {       PlayerPiece shape = new PlayerPiece();       shape.displayShape();       shape.movePiece();    } }  
    • A. 

      PlayingPiece class inherits the generic movePiece() method

    • B. 

      PlayingPiece class inherits the generic displayShape() method

    • C. 

      GameShape class inherits the generic displayShape() method

    • D. 

      GameShape class inherits the generic movePiece() method

  • 18. 
    The two most common reasons to use inheritance are( choose 2)
    • A. 

      To promote code reuse

    • B. 

      To use abstraction

    • C. 

      To use interface

    • D. 

      To use polymorphism

  • 19. 
    Examples of class are( choose 3)  
    • A. 

      White

    • B. 

      Length

    • C. 

      Classroom

    • D. 

      Car

    • E. 

      Person

  • 20. 
    In OO, the concept of IS-A is based on  
    • A. 

      Class inheritance

    • B. 

      Interface implementation.

    • C. 

      Both

    • D. 

      None

  • 21. 
    The benefits of the Object Orientation are: ( choose two )
    • A. 

      Inheritance

    • B. 

      Flexibility

    • C. 

      Maintainability

    • D. 

      Polymorphism

  • 22. 
    If you don't have the access to the source code for a class, but you want to change the way a method of that class works, then could you use subclassing to do that that is to extend the "bad" class and override the method with your own better code? 
    • A. 

      True

    • B. 

      False

Back to Top Back to top