Programming Using Java Unit 1 MCQ

Programming Using Java

Unit 1 MCQ

Programming Using Java Unit 1 MCQ


Which of the following is valid declaration of object in java?

  1. Boy obj = new Boy;
  2. Boy obj = new Boy();
  3. obj = new Boy();
  4. new Boy obj;

Answer: Boy obj = new Boy();

Which of the following statement is incorrect?

  1. main() method is public
  2. We can have more than one class in a single java source file.
  3. Every java class must contain main() method
  4. super is used to call parent class method or constructor

Answer: Every java class must contain main() method

What is a suitable return type of a method that does not return any value?

  1. int
  2. float
  3. double
  4. void

Answer: void

Which of the following entity has same name as that of the class?

  1. method
  2. sub-class
  3. clone-able object
  4. constructor

Answer: constructor

Which can be declared only once in a program?

  1. main() method
  2. static method
  3. private method
  4. final method

Answer: main() method

Which keyword is used to refer to the current object that invoked it?

  1. super
  2. static
  3. transient
  4. this

Answer: this

Which operator is in Java to free the garbage memory?

  1. free
  2. new
  3. dealloc
  4. none of the above.

Answer: none of the above.

Which method is called by garbage collector before it claims the garbage?

  1. final
  2. finalize
  3. deserialize
  4. none of the above

Answer: finalize

What would be behavior if constructor has a return type?

  1. runtime error
  2. normal flow
  3. compilation error
  4. none of the above

Answer: compilation error

What is true about constructor?

  1. Constructors cannot be synchronized in Java
  2. Java does not provide default copy constructor
  3. Constructor can be overloaded
  4. "this" and "super" can be used in a constructor

Answer: Constructor can be overloaded

Post a Comment