Professional Documents
Culture Documents
a) super
b) this
c) extent
d) extends
Answer: d
Which of these keywords is used to refer to member of base class from a sub class?
a) upper
b) super
c) this
d) none of the mentioned
Answer: b
Answer: b
Answer: c
a) 0
b) 1
c) 2
d) Compilation Error
Answer: c
a) 2 2
b) 3 3
c) 2 3
d) 3 2
Answer: c
a) 2 2
b) 3 3
c) Runtime Error
d) Compilation Error
Answer: d
What will be the output
1. class A
2. {
3. public int i;
4. public int j;
5. A()
6. {
7. i = 1;
8. j = 2;
9. }
10. }
11. class B extends A
12. {
13. int a;
14. B()
15. {
16. super();
17. }
18. }
19. class super_use
20. {
21. public static void main(String args[])
22. {
23. B obj = new B();
24. System.out.println(obj.i + " " + obj.j;
25. }
26. }
a) 1 2
b) 2 1
c) Runtime Error
d) Compilation Error
Answer: a
Answer: d
Explanation: All classes in java are inherited from Object class. Interfaces are not inherited
from Object Class.
In order to restrict a variable of a class from inheriting to sub class, how variable should be
declared?
a) Protected
b) Private
c) Public
d) Static
Answer: b
Explanation: By declaring variable private, the variable will not be available in inherited to
sub class.
If super class and sub class have same variable name, which keyword should be used to use
super class?
a) super
b) this
c) upper
d) classname
Answer: a
Explanation: Super keyword is used to access hidden super class variable in sub class.
What would be the result if class extends two interfaces and both have method with same
name and signature?
a) Runtime error
b) Compile time error
c) Code runs successfully
d) First called method is executed successfully
Answer: b
Explanation: In case of such conflict, compiler will not be able to link a method call due to
ambiguity. It will throw compile time error.