-->

Object oriented programming Java -3 || diplomachakhazana

diplomachakhazana



 JOIN US

Sr.no Select Any Option
1 Object Oriented Programming Java MCQ Page 1
2 Object Oriented Programming Java MCQ Page 2
3 Object Oriented Programming Java MCQ Page 3
4 Object Oriented Programming Java MCQ Page 4

Object oriented programming Java

1. Break statement in switch case

a.prevents from fallthrough

b.causes an exit from innermost loop

c.both a and b

d.none

Answer: C


2. The keyword 'this' is used

a. As reference to current object

b. Explicit constructor invocation

c. In open recursion

d. All the above

Answer: D


3. When does method overloading is determined?
a) At run time
b) At compile time
c) At coding time
d) At execution time

Answer: b

4. When Overloading does not occur?
a) More than one method with same name but different method signature and different number or type of parameters
b) More than one method with same name, same signature but different number of signature

c) More than one method with same name, same signature, same number of parameters but different type
d) More than one method with same name, same number of parameters and type but different signature

Answer: d


5. Method overriding is combination of inheritance and polymorphism?
a) True
b) false

Answer: a


6. What is the stored in the object obj in following lines of Java code?

   box obj;

a) Memory address of allocated memory of object
b) NULL
c) Any arbitrary pointer
d) Garbage

Answer: b

7. Which of these keywords is used to make a class?
a) class
b) struct
c) int
d) none of the mentioned

Answer: a


8. Which of the following is a valid declaration of an object of class Box?
a) Box obj = new Box();
b) Box obj = new Box;
c) obj = new Box();
d) new Box obj;

Answer: a


9. Which of these operators is used to allocate memory for an object?
a) malloc
b) alloc
c) new
d) give

Answer: c


10. Which of these statement is incorrect?
a) Every class must contain a main() method
b) Applets do not require a main() method at all
c) There can be only one main() method in a program
d) main() method must be made public

Answer: a


11. What will be the output of the following Java program?



  1.     class main_class 

  2.     {

  3.         public static void main(String args[])

  4.         {

  5.             int x = 9;

  6.             if (x == 9) 

  7.             { 

  8.                 int x = 8;

  9.                 System.out.println(x);

  10.             }

  11.         } 

  12.     }


a) 9
b) 8
c) Compilation error
d) Runtime error

Answer: c


12. Which of the following statements is correct?
a) Public method is accessible to all other classes in the hierarchy
b) Public method is accessible only to subclasses of its parent class
c) Public method can only be called by object of its class
d) Public method can be accessed by calling object of the public class

Answer: a




13. What will be the output of the following Java program?



  1.      class box 

  2.     {

  3.         int width;

  4.         int height;

  5.         int length;

  6.     } 

  7.     class mainclass 

  8.     {

  9.         public static void main(String args[]) 

  10.         {        

  11.              box obj = new box();

  12.              obj.width = 10;

  13.              obj.height = 2;

  14.              obj.length = 10;

  15.              int y = obj.width * obj.height * obj.length; 

  16.              System.out.print(y);

  17.         } 

  18.     }


a) 12
b) 200
c) 400
d) 100

Answer: b


14. What will be the output of the following Java program?

    

  1.      class box

  2.    {

  3.         int width;

  4.         int height;

  5.         int length;

  6.     } 

  7.     class mainclass 

  8.     {

  9.         public static void main(String args[]) 

  10.         {        

  11.             box obj1 = new box();

  12.             box obj2 = new box();

  13.             obj1.height = 1;

  14.             obj1.length = 2;

  15.             obj1.width = 1;

  16.             obj2 = obj1;

  17.             System.out.println(obj2.height);

  18.         } 

  19.     }


a) 1
b) 2
c) Runtime error
d) Garbage value

Answer: a


15. What will be the output of the following Java program?



  1.     class box 

  2.    {

  3.         int width;

  4.         int height;

  5.         int length;

  6.    } 

  7.     class mainclass 

  8.     {

  9.         public static void main(String args[]) 

  10.         {        

  11.             box obj = new box();

  12.             System.out.println(obj);

  13.         } 

  14.     }


a) 0
b) 1
c) Runtime error
d)classname@hashcode in hexadecimal form

Answer: d



16. What is the process of defining two or more methods within same class that have same name but different parameters declaration?
a) method overloading
b) method overriding
c) method hiding
d) none of the mentioned

Answer: a


17. Which of these can be overloaded?
a) Methods
b) Constructors
c) All of the mentioned
d) None of the mentioned

Answer: c


18. What will be the output of the following Java code?


  1.   class San

  2.  {

  3.  public void m1 (int i,float f)

  4.  {

  5.   System.out.println(" int float method");

  6.  }

  7.  

  8.  public void m1(float f,int i);

  9.   {

  10.   System.out.println("float int method");

  11.   }

  12.  

  13.   public static void main(String[]args)

  14.   {

  15.     San s=new San();

  16.         s.m1(20,20);

  17.   }

  18. }



a) int float method
b) float int method
c) compile time error
d) run time error

Answer: c






19. What will be the output of the following Java code?


  1.      class overload  

  2.  {

  3.         int x;

  4.         int y;

  5.         void add(int a) 

  6.         {

  7.             x =  a + 1;

  8.         }

  9.         void add(int a, int b)

  10.         {

  11.             x =  a + 2;

  12.         }        

  13.     }    

  14.     class Overload_methods 

  15.     {

  16.         public static void main(String args[])

  17.         {

  18.             overload obj = new overload();   

  19.             int a = 0;

  20.             obj.add(6);

  21.             System.out.println(obj.x);     

  22.         }

  23.    }


a) 5
b) 6
c) 7
d) 8

Answer: c

20. What will be the output of the following Java code?

 

  1.    class overload 

  2.    {

  3.         int x;

  4.         int y;

  5.         void add(int a)

  6.         {

  7.             x =  a + 1;

  8.         }

  9.         void add(int a , int b)

  10.         {

  11.             x =  a + 2;

  12.         }        

  13.     }    

  14.     class Overload_methods 

  15.     {

  16.         public static void main(String args[])

  17.         {

  18.             overload obj = new overload();   

  19.             int a = 0;

  20.             obj.add(6, 7);

  21.             System.out.println(obj.x);     

  22.         }

  23.     }



a) 6
b) 7
c) 8
d) 9


Answer: c


21. What will be the output of the following Java code?

  1.    class overload  {

  2.         int x;

  3.         double y;

  4.         void add(int a , int b) 

  5.         {

  6.             x = a + b;

  7.         }

  8.         void add(double c , double d)

  9.         {

  10.             y = c + d;

  11.         }

  12.         overload() 

  13.         {

  14.             this.x = 0;

  15.             this.y = 0;

  16.         }        

  17.     }    

  18.     class Overload_methods     {

  19.         public static void main(String args[])

  20.         {

  21.             overload obj = new overload();   

  22.             int a = 2;

  23.             double b = 3.2;

  24.             obj.add(a, a);

  25.             obj.add(b, b);

  26.             System.out.println(obj.x + " " + obj.y);     

  27.         }

  28.    }


a) 6 6
b) 6.4 6.4
c) 6.4 6
d) 4 6.4

Answer: d


22. What will be the output of the following Java code?



  1.     class test 

  2.   {

  3.         int a;

  4.         int b;

  5.         void meth(int i , int j) 

  6.         {

  7.             i *= 2;

  8.             j /= 2;

  9.         }          

  10.     }    

  11.     class Output 

  12.     {

  13.         public static void main(String args[])

  14.         {

  15.             test obj = new test();

  16.             int a = 10;

  17.             int b = 20;             

  18.             obj.meth(a , b);

  19.             System.out.println(a + " " + b);        

  20.         } 

  21.     }

a) 10 20
b) 20 10
c) 20 40
d) 40 20

Answer: a



23. What will be the output of the following Java code?



  1.    class test 

  2.   {

  3.         int a;

  4.         int b;

  5.         test(int i, int j) 

  6.         {

  7.             a = i;

  8.             b = j;

  9.         }

  10.         void meth(test o) 

  11.         {

  12.             o.a *= 2;

  13.             O.b /= 2;

  14.         }          

  15.     }    

  16.     class Output 

  17.     {

  18.         public static void main(String args[])

  19.         {

  20.             test obj = new test(10 , 20);

  21.             obj.meth(obj);

  22.             System.out.println(obj.a + " " + obj.b);        

  23.         } 

  24.     }


a) 10 20
b) 20 10
c) 20 40
d) 40 20

Answer: b



24. Which of these is the method which is executed first before execution of any other thing takes place in a program?
a) main method
b) finalize method
c) static method
d) private method

Answer: c

25. What is the process of defining more than one method in a class differentiated by parameters?
a) Function overriding
b) Function overloading
c) Function doubling
d) None of the mentioned

Answer: b


26. Which of these can be used to differentiate two or more methods having the same name?
a) Parameters data type
b) Number of parameters
c) Return type of method
d) All of the mentioned

Answer: d

27. Which of these data type can be used for a method having a return statement in it?
a) void
b) int
c) float
d) both int and float

Answer: d


28. Which of these statement is incorrect?
a) Two or more methods with same name can be differentiated on the basis of their parameters data type
b) Two or more method having same name can be differentiated on basis of number of parameters
c) Any already defined method in java library can be defined again in the program with different data type of parameters
d) If a method is returning a value the calling statement must have a variable to store that value

Answer: d


29. 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.         public static void main(String args[]) 

  14.         {

  15.             box obj = new box();

  16.             obj.height = 1;

  17.             obj.length = 5;

  18.             obj.width = 5;

  19.             obj.volume(3, 2, 1);

  20.             System.out.println(obj.volume);        

  21.         } 

  22.     }

a) 0
b) 1
c) 6
d) 25

Answer: c

30. 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.     }


a) false
b) true
c) 0
d) 1

Answer: b

31. 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.         void volume(int x) 

  12.         {

  13.             volume = x;

  14.         }

  15.     }    

  16.     class Output 

  17.     { 

  18.         public static void main(String args[]) 

  19.         {

  20.             box obj = new box();

  21.             obj.height = 1;

  22.             obj.length = 5;

  23.             obj.width = 5;

  24.             obj.volume(5);

  25.             System.out.println(obj.volume);        

  26.         } 

  27.     }


a) 0
b) 5
c) 25
d) 26

Answer: b

32. What will be the output of the following Java program?



  1.  class Output   

  2.   

  3.         static void main(String args[]) 

  4.         {    

  5.              int x , y = 1;

  6.              x = 10;

  7.              if(x != 10 && x / 0 == 0)

  8.                  System.out.println(y);

  9.              else

  10.                  System.out.println(++y);

  11.         } 

  12.     }

a) 1
b) 2
c) Runtime Error
d) Compilation Error

Answer: d

33. What will be the output of the following Java program?


  1.    class area 

  2.   {

  3.         int width;

  4.         int length;

  5.         int height;

  6.         area() 

  7.         {

  8.         width = 5;

  9.         length = 6;

  10.         height = 1;

  11.         }

  12.         void volume() 

  13.         {

  14.              volume = width * height * length;

  15.         } 

  16.     }    

  17.     class cons_method 

  18.     {

  19.         public static void main(String args[]) 

  20.         {

  21.             area obj = new area();

  22.             obj.volume();

  23.             System.out.println(obj.volume);

  24.         } 

  25.     }


a) 0
b) 1
c) 25
d) 30

Answer: d

34. Which of these keywords is used to prevent content of a variable from being modified?
a) final
b) last
c) constant
d) static

Answer: a

35. Which of these cannot be declared static?
a) class
b) object
c) variable
d) method

Answer: b

36. Which of the following statements are incorrect?
a) static methods can call other static methods only
b) static methods must only access static data
c) static methods can not refer to this or super in any way
d) when object of class is declared, each object contains its own copy of static variables

Answer: d

37. Which of the following statements are incorrect?
a) Variables declared as final occupy memory
b) final variable must be initialized at the time of declaration
c) Arrays in java are implemented as an object
d) All arrays contain an attribute-length which contains the number of elements stored in the array

Answer: a

38. Which of these methods must be made static?
a) main()
b) delete()
c) run()
d) finalize()

Answer: a

39. What will be the output of the following Java program?


  1.    class access

  2.   {

  3.         public int x;

  4.         static int y;

  5.         void cal(int a, int b)

  6.         {

  7.             x +=  a ;

  8.             y +=  b;

  9.         }        

  10.     }    

  11.     class static_specifier 

  12.     {

  13.         public static void main(String args[])

  14.         {

  15.             access obj1 = new access();

  16.             access obj2 = new access();   

  17.             obj1.x = 0;

  18.             obj1.y = 0;

  19.             obj1.cal(1, 2);

  20.             obj2.x = 0;

  21.             obj2.cal(2, 3);

  22.             System.out.println(obj1.x + " " + obj2.y);     

  23.         }

  24.    }

a) 1 2
b) 2 3
c) 3 2
d) 1 5

Answer: d




40. What will be the output of the following Java program?



  1.     class access

  2.  {

  3.        static int x;

  4.        void increment()

  5.        {

  6.            x++;

  7.        }   

  8.      }   

  9.     class static_use 

  10.     {

  11.         public static void main(String args[])

  12.         {

  13.             access obj1 = new access();

  14.             access obj2 = new access();

  15.             obj1.x = 0;   

  16.             obj1.increment();

  17.             obj2.increment();

  18.             System.out.println(obj1.x + " " + obj2.x);

  19.          }

  20.    }

a) 1 2
b) 1 1
c) 2 2
d) Compilation Error

Answer: c

41. What will be the output of the following Java program?


  1.     class static_out 

  2.   {

  3.         static int x;

  4.         static int y;

  5.         void add(int a , int b)

  6.         {

  7.             x = a + b;

  8.             y = x + b;

  9.         }

  10.     }    

  11.     class static_use 

  12.     {

  13.         public static void main(String args[])

  14.         {

  15.             static_out obj1 = new static_out();

  16.             static_out obj2 = new static_out();   

  17.             int a = 2;

  18.             obj1.add(a, a + 1);

  19.             obj2.add(5, a);

  20.             System.out.println(obj1.x + " " + obj2.y);     

  21.         }

  22.    }


a) 7 7
b) 6 6
c) 7 9
d) 9 7

Answer: c

42. What will be the output of the following Java program?


  1.    class Output 

  2.  {

  3.         public static void main(String args[])

  4.         {

  5.             int arr[] = {1, 2, 3, 4, 5};

  6.             for ( int i = 0; i < arr.length - 2; ++i)

  7.                 System.out.println(arr[i] + " ");

  8.         } 

  9.     }

a) 1 2
b) 1 2 3
c) 1 2 3 4
d) 1 2 3 4 5
Answer: b

43. What will be the output of the following Java program?


  1.    class Output  

  2.   {

  3.         public static void main(String args[])

  4.         {

  5.             int a1[] = new int[10];

  6.             int a2[] = {1, 2, 3, 4, 5};

  7.             System.out.println(a1.length + " " + a2.length);

  8.         } 

  9.     }


a) 10 5
b) 5 10
c) 0 10
d) 0 5

Answer: a

44. What is the return type of a method that does not return any value?
a) int
b) float
c) void
d) double

Answer: c

45. What is the process of defining more than one method in a class differentiated by method signature?
a) Function overriding
b) Function overloading
c) Function doubling
d) None of the mentioned

Answer: b

46. Which of the following is a method having same name as that of it’s class?
a) finalize
b) delete
c) class
d) constructor

Answer: d

47. Which method can be defined only once in a program?
a) main method
b) finalize method
c) static method
d) private method

Answer: a


48. Which of this statement is incorrect?
a) All object of a class are allotted memory for the all the variables defined in the class
b) If a function is defined public it can be accessed by object of other class by inheritation
c) main() method must be made public
d) All object of a class are allotted memory for the methods defined in the class

Answer: d

49. 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.      }

a) 0
b) 1
c) 6
d) 25

Answer: c

50. 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.     }



a) false
b) true
c) 0
d) 1

Answer: b

51. 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.     }

a) 0
b) 1
c) 25
d) 26

Answer: c

52. 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. }

a) only sum(10)
b) only sum(10,20)
c) only sum(10) & sum(10,20)
d) all of the mentioned

Answer: d

53. 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.     }

a) 0
b) 1
c) 30
d) error

Answer: d

54. What is an array of objects?
a) An array of instances of class represented by single name
b) An array of instances of class represented by more than one name
c) An array of instances which have more than 2 instances
d) An array of instances which have different types

Answer: a

55. Which among the following is a mandatory condition for array of objects?
a) All the objects should be of different class
b) All the objects should be of same program classes
c) All the objects should be of same class
d) All the objects should have different data

Answer: c

56. What is the type of elements of array of objects?
a) Class
b) Void
c) String
d) Null

Answer: a

57. If array of objects is declared as given below, which is the limitation on objects?

Class_name arrayName[size];

a) The objects will have same values
b) The objects will not be initialized individually
c) The objects can never be initialized
d) The objects will have same data

Answer: b

58. Which is the condition that must be followed if the array of objects is declared without initialization, only with size of array?
a) The class should have separate constructor for each object
b) The class must have no constructors
c) The class should not have any member function
d) The class must have a default or zero argument constructor

Answer: d

59. When are the array of objects without any initialization useful?
a) When object data is not required just after the declaration
b) When initialization of object data is to be made by the compiler
c) When object data doesn’t matter in the program
d) When the object should contain garbage data

Answer: a

60. If constructor arguments are passed to objects of array then ____________ if the constructors are overloaded.
a) It is mandatory to pass same number of arguments to all the objects
b) It is mandatory to pass same type of arguments to all the objects
c) It is not mandatory to call same constructor for all the objects
d) It is mandatory to call same constructor for all the constructors

Answer: c

61. How the objects of array can be denoted?
a) Indices
b) Name
c) Random numbers
d) Alphabets

Answer: a

62. The objects in an object array _______________________
a) Can be created without use of constructor
b) Can be created without calling default constructor
c) Can’t be created with use of constructor
d) Can’t be created without calling default constructor

Answer: b

63. The Object array is created in _____________________
a) Heap memory
b) Stack memory
c) HDD
d) ROM

Answer: a

64. If an array of objects is of size 10 and a data value have to be retrieved from 5th object then ________________ syntax should be used.
a) Array_Name[4].data_variable_name;
b) Data_Type Array_Name[4].data_variable_name;
c) Array_Name[4].data_variable_name.value;
d) Array_Name[4].data_variable_name(value);

Answer: a

65. Can we have two dimensional object array?
a) Yes, always
b) Yes, only if primitive type array
c) No, since two indices are impossible
d) No, never

Answer: a

66. From which index does the array of objects start?
a) 0
b) 1
c) 2
d) 3

Answer: a

67. Two dimensional array can’t be initialized with the declaration.
a) True
b) False

Answer: b

68. Is an array of characters always a string?
a) Yes, always
b) Yes, if each character is terminated by null
c) No, since each character is terminated by null
d) No, never

Answer: d


69. In which of the following way(s) can the object be returned from a function?
a) Can only be returned by value
b) Can only be returned by reference
c) Can be returned either by value or reference
d) Can neither be returned by value nor by reference

Answer: c

70. Whenever an object is returned by value ____________________
a) A temporary object is created
b) Temporary object is not created
c) Temporary object may or may not be created
d) New permanent object is created

Answer: a

71. Where the temporary objects (created while return by value) are created?
a) Outside the function scope
b) Within the function
c) Inside the main function
d) Inside the calling function
Answer: b


72. Which is the correct syntax for returning an object by value?
a) void functionName ( ){ }
b) object functionName( ) { }
c) class object functionName( ) { }
d) ClassName functionName ( ){ }

Answer: d


73. If an object is declared inside the function then ____________________ outside the function.
a) It can be returned by reference
b) It can’t be returned by reference
c) It can be returned by address
d) It can’t be returned at all

Answer: b


74. How many independent objects can be returned at same time from a function?
a) 1
b) 2
c) 3
d) 4

Answer: a


75. Which error will be produced if a local object is returned by reference outside a function?
a) Out of memory error
b) Run time error
c) Compile time error
d) No error

Answer: c




76. Which of these class is superclass of every class in Java?
a) String class
b) Object class
c) Abstract class
d) ArrayList class

Answer: b


77. Which of these keywords can be used to prevent inheritance of a class?
a) super
b) constant
c) class
d) final

Answer: d


78. Which of these keywords cannot be used for a class which has been declared final?
a) abstract
b) extends
c) abstract and extends
d) none of the mentioned

Answer: a


79. Which of these class relies upon its subclasses for complete implementation of its methods?
a) Object class
b) abstract class
c) ArrayList class
d) None of the mentioned

Answer: b


80. What will be the output of the following Java program?


  1.    abstract class

  2.  {

  3.         int i;

  4.         abstract void display();

  5.     }    

  6.     class B extends

  7.     {

  8.         int j;

  9.         void display() 

  10.         {

  11.             System.out.println(j);

  12.         }

  13.     }    

  14.     class Abstract_demo 

  15.     {

  16.         public static void main(String args[])

  17.         {

  18.             B obj = new B();

  19.             obj.j=2;

  20.             obj.display();    

  21.         }

  22.     }


a) 0
b) 2
c) Runtime Error
d) Compilation Error

Answer: b

81. What will be the output of the following Java program?

 

  1.   class

  2.  {

  3.         int i;

  4.         int j;

  5.         A() 

  6.         {

  7.             i = 1;

  8.             j = 2;

  9.         }

  10.    }

  11.    class Output 

  12.    {

  13.         public static void main(String args[])

  14.         {

  15.              A obj1 = new A();

  16.              A obj2 = new A();

  17.              System.out.print(obj1.equals(obj2));

  18.         }

  19.    }

a) false
b) true
c) 1
d) Compilation Error

Answer: a

82. What will be the output of the following Java code?


  1.    class Output 

  2.  {

  3.         public static void main(String args[])

  4.         {

  5.              Object obj = new Object();

  6.              System.out.print(obj.getclass());

  7.         }

  8.     }

a) Object
b) class Object
c) class java.lang.Object
d) Compilation Error

Answer: c


83. What will be the output of the following Java code?


  1.      class

  2.  {

  3.         int i;

  4.         int j;

  5.         A() 

  6.         {

  7.             i = 1;

  8.             j = 2;

  9.         }

  10.    }

  11.    class Output 

  12.    {

  13.         public static void main(String args[])

  14.         {

  15.              A obj1 = new A();

  16.              System.out.print(obj1.toString());

  17.         }

  18.    }

a) true
b) false
c) String associated with obj1
d) Compilation Error

Answer: c

84. What is the new operator?
a) Allocates memory for an object or array
b) Allocates memory for an object or array and returns a particular pointer
c) Used as return type when an object is created
d) Used to declare any new thing in a program

Answer: b

85. The new operator _____________
a) Can allocate reference types too
b) Doesn’t allocate reference types
c) Can allocate reference to objects
d) Doesn’t allocate any data

Answer: b

86. Which among the following is true?
a) New operator can’t allocate functions but pointer to functions can be allocated
b) New operator can allocate functions as well as pointer to functions
c) New operator can allocate any type of functions
d) New operator is not applicable with functions allocation

Answer: a

87. Which among the following is added in grammar of new operator?
a) Finalize
b) Arg
c) Initializer
d) Allocator

Answer: c

88. Initializers __________________
a) Are used for specifying arrays
b) Are used to defined multidimensional arrays
c) Can’t be specified for arrays
d) Can’t be specified for any data

Answer: c

89. The objects allocated using new operator ________________
a) Are destroyed when they go out of scope
b) Are not destroyed even if they go out of scope
c) Are destroyed anytime
d) Are not destroyed throughout the program execution

Answer: b

90. The new operator _________________
a) Invokes function operator new
b) Doesn’t invoke function operator new
c) Invokes function operator only if required
d) Can’t invoke function operator new implicitly

Answer: a

91. If a new operator is defined for a class and still global new operator have to be used, which operator should be used with the keyword new?
a) Colon
b) Arrow
c) Dot
d) Scope resolution

Answer: d


 

 



diplomachakhazana


null

0 Comments