Java - Online Test - Composition - javasearch.buggybread.com


Share

Search Java Test Questions


 223 test questions in repository.




Java - Test Questions on 'Composition' - 6 questions found


What is the relationship between Vehicle and Engine in this example ?

public class Vehicle {
   Enginer engine;
   public void move(){
      engine = new Engine();
      engine.start();
   }
}
Core Java
Composition ( Vehicle has a Engine )
Composition ( Engine has a Vehicle )
Inheritance ( Vehicle is a Engine )
Inheritance ( Engine is a Vehicle )

  composition  inheritance  oops concepts

What is the relationship between Car and Vehicle in the following code ?

public class Car extends Vehicle{
   Engine engine;   
   
   public static void main(String[] args){
      Vehicle vehicle = new Car();
      car.move();
   }   

   public void move(){
      engine = new Engine();
      engine.start();
   }
}
Core Java
Composition ( Vehicle has a Car )
Composition ( Car has a Vehicle )
Inheritance ( Vehicle is a Car )
Inheritance ( Car is a Vehicle )

  Inheritance  Composition  Oops concepts

What is the problem with the following code ?

public class Car extends Vehicle{
   Vehicle vehicle;
   
   Car(){
      super();
      this.vehicle = new Vehicle();
   }
}
Core Java
There is an Inheritance as well as Composition relationship between Vehicle and Car which is not permitted
We cannot initialize the parent class instance within the constructor
Call to super is illegal
There is no problem

  Composition  Inheritance  OOPS concepts

Which of the following Java feature promotes access protection or Hiding ?Core Java
Inheritance
Encapsulation
Abstraction
Composition

  java  java concepts  java features  oops concepts  oops features  access protection  information hiding

Which of the following is true ?Core Java
Composition is Tightly Bound
Inheritance is Tightly Bound
Object can only hold reference of only one other object
A Class cannot be extended by multiple classes

  

if classes B and C extends Class A, Which of the following initialization is correct ?Core Java
B b = new C();
C c = new B();
B b = new A();
A a = new B();

  inheritance







comments powered by Disqus