Java Mcqs
Java Mcqs
Java Mcqs
a) Private constructor ensures only one instance of a class exist at any point of time
b) Private constructor ensures multiple instances of a class exist at any point of time
c) Private constructor eases the instantiation of a class
d) Private constructor allows creating objects in other classes
View Answer
1. Which of this keyword can be used in a subclass to call the constructor of superclass?
a) super
b) this
c) extent
d) extends
View Answer
2. What is the process of defining a method in a subclass having same name & type signature as a
method in its superclass?
a) Method overloading
b) Method overriding
c) Method hiding
d) None of the mentioned
View Answer
5. At line number 2 below, choose 3 valid data-type attributes/qualifiers among “final, static, native,
public, private, abstract, protected”
a) 2
b) 3
c) 7
d) Compilation Error
View Answer
1. final class A
2. {
3. int i;
4. }
5. class B extends A
6. {
7. int j;
8. System.out.println(j + " " + i);
9. }
10. class inheritance
11. {
12. public static void main(String args[])
13. {
14. B obj = new B();
15. obj.display();
16. }
17. }
a) 2 2
b) 3 3
c) Runtime Error
d) Compilation Error
View Answer
9. What is the output of this program?
1. class Abc
2. {
3. public static void main(String[]args)
4. {
5. String[] elements = { "for", "tea", "too" };
6. String first = (elements.length > 0) ? elements[0]: null;
7. }
8. }
a) Compilation error
b) An exception is thrown at run time
c) The variable first is set to null
d) The variable first is set to elements[0].
View Answer