Programming Using Java
Unit 1 MCQ
UNIT 1 MCQ OF PROGRAMMING USING JAVA
Which of the following is valid declaration of object in java?
- Boy obj = new Boy;
- Boy obj = new Boy();
- obj = new Boy();
- new Boy obj;
Answer: Boy obj = new Boy();
Which of the following statement is incorrect?
- main() method is public
- We can have more than one class in a single java source file.
- Every java class must contain main() method
- 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?
- int
- float
- double
- void
Answer: void
Which of the following entity has same name as that of the class?
- method
- sub-class
- clone-able object
- constructor
Answer: constructor
Which can be declared only once in a program?
- main() method
- static method
- private method
- final method
Answer: main() method
Which keyword is used to refer to the current object that invoked it?
- super
- static
- transient
- this
Answer: this
Which operator is in Java to free the garbage memory?
- free
- new
- dealloc
- none of the above.
Answer: none of the above.
Which method is called by garbage collector before it claims the garbage?
- final
- finalize
- deserialize
- none of the above
Answer: finalize
What would be behavior if constructor has a return type?
- runtime error
- normal flow
- compilation error
- none of the above
Answer: compilation error
What is true about constructor?
- Constructors cannot be synchronized in Java
- Java does not provide default copy constructor
- Constructor can be overloaded
- "this" and "super" can be used in a constructor
Answer: Constructor can be overloaded