Java Quiz 11 : Classes & Methods II

    Welcome to your Java Quiz 11 : Classes & Methods II

    1. What will be the output of the following Java program?
    1.  class box 
    2.  {
    3.  int width;
    4.  int height;
    5.  int length;
    6.  int volume;
    7.  void volume(int height, int length, int width) 
    8.  {
    9.  volume = width*height*length;
    10.  } 
    11.  } 
    12.  class Prameterized_method
    13.  {
    14.  public static void main(String args[])
    15.  {
    16.  box obj = new box();
    17.  obj.height = 1;
    18.  obj.length = 5;
    19.  obj.width = 5;
    20.  obj.volume(3,2,1);
    21.  System.out.println(obj.volume); 
    22.  } 
    23.  }
    2. What will be the output of the following Java program?
    1.  class equality 
    2.  {
    3.  int x;
    4.  int y;
    5.  boolean isequal()
    6.  {
    7.  return(x == y); 
    8.  } 
    9.  } 
    10.  class Output 
    11.  {
    12.  public static void main(String args[])
    13.  {
    14.  equality obj = new equality();
    15.  obj.x = 5;
    16.  obj.y = 5;
    17.  System.out.println(obj.isequal());
    18.  } 
    19.  }
    3. What will be the output of the following Java program?
    1.  class box 
    2.  {
    3.  int width;
    4.  int height;
    5.  int length;
    6.  int volume;
    7.  void volume() 
    8.  {
    9.  volume = width*height*length;
    10.  } 
    11.  } 
    12.  class Output 
    13.  { 
    14.  public static void main(String args[])
    15.  {
    16.  box obj = new box();
    17.  obj.height = 1;
    18.  obj.length = 5;
    19.  obj.width = 5;
    20.  obj.volume();
    21.  System.out.println(obj.volume); 
    22.  } 
    23.  }
    4. In the following Java code, which call to sum() method is appropriate?
    1. class Output 
    2. {
    3.  
    4.  public static int sum(int ...x)
    5.  {
    6.  return; 
    7.  }
    8.  static void main(String args[]) 
    9.  { 
    10.  sum(10);
    11.  sum(10,20);
    12.  sum(10,20,30);
    13.  sum(10,20,30,40);
    14.  } 
    15. }
    5. What will be the output of the following Java program?
    1.  class area 
    2.  {
    3.  int width;
    4.  int length;
    5.  int volume;
    6.  area() 
    7.  {
    8.  width=5;
    9.  length=6;
    10.  }
    11.  void volume() 
    12.  {
    13.  volume = width*length*height;
    14.  } 
    15.  } 
    16.  class cons_method 
    17.  {
    18.  public static void main(String args[])
    19.  {
    20.  area obj = new area();
    21.  obj.volume();
    22.  System.out.println(obj.volume); 
    23.  } 
    24.  }
    6. What is the return type of Constructors?
    7. Which keyword is used by the method to refer to the object that invoked it?
    8. Which of the following is a method having same name as that of its class?
    9. Which operator is used by Java run time implementations to free the memory of an object when it is no longer needed?
    10. Which function is used to perform some action when the object is to be destroyed?
    11. What will be the output of the following Java code?
    1.  class box 
    2.  {
    3.  int width;
    4.  int height;
    5.  int length;
    6.  int volume;
    7.  box() 
    8.  {
    9.  width = 5;
    10.  height = 5;
    11.  length = 6;
    12.  }
    13.  void volume() 
    14.  {
    15.  volume = width*height*length;
    16.  } 
    17.  } 
    18.  class constructor_output 
    19.  {
    20.  public static void main(String args[])
    21.  {
    22.  box obj = new box();
    23.  obj.volume();
    24.  System.out.println(obj.volume);
    25.  }
    26.  }
    12. What will be the output of the following Java code?
    1. class San
    2. {
    3.  San()throws IOException
    4.  {
    5.  
    6.  } 
    7.  
    8. }
    9. class Foundry extends San
    10. {
    11.  Foundry()
    12.  {
    13.  
    14.  }
    15.  public static void main(String[]args)
    16.  {
    17.  
    18.  }
    19. }
    13. What will be the output of the following Java code?
    1.  class box 
    2.  {
    3.  int width;
    4.  int height;
    5.  int length;
    6.  int volume;
    7.  void finalize() 
    8.  {
    9.  volume = width*height*length;
    10.  System.out.println(volume);
    11.  }
    12.  protected void volume() 
    13.  {
    14.  volume = width*height*length;
    15.  System.out.println(volume);
    16.  } 
    17.  } 
    18.  class Output 
    19.  { 
    20.  public static void main(String args[])
    21.  {
    22.  box obj = new box();
    23.  obj.width=5;
    24.  obj.height=5;
    25.  obj.length=6;
    26.  obj.volume();
    27.  } 
    28.  }
    14. Which of the following statements are incorrect?
    15. What will be the output of the following Java code?
    1.  class area 
    2.  {
    3.  int width;
    4.  int length;
    5.  int area;
    6.  void area(int width, int length) 
    7.  {
    8.  this.width = width;
    9.  this.length = length;
    10.  }
    11.  
    12.  } 
    13.  class Output 
    14.  {
    15.  public static void main(String args[])
    16.  {
    17.  area obj = new area();
    18.  obj.area(5 , 6);
    19.  System.out.println(obj.length + " " + obj.width); 
    20.  } 
    21.  }