Abstract, Inner, Static Classes Questions: Class Public Public
Abstract, Inner, Static Classes Questions: Class Public Public
2. class A
3. {
4. public int i;
5. public int j;
6. A()
7. {
8. i = 1;
9. j = 2;
10. }
11. }
12. class B extends A
13. {
14. int a;
15. B()
16. {
17. super();
18. }
19. }
20. class super_use
21. {
22. public static void main(String args[])
23. {
24. B obj = new B();
25. System.out.println(obj.i + " " + obj.j)
26. }
27. }
a) 1 2
b) 2 1
c) Runtime Error
d) Compilation Error
6: Why can outer Java classes access inner class private members?
7. What is the main difference between static and non-static nested classes? Also provide an
example for each of them?
9. Create an abstract class 'Animals' with two abstract methods 'cats' and 'dogs'. Now create a class 'Cats'
with a method 'cats' which prints "Cats meow" and a class 'Dogs' with a method 'dogs' which prints "Dogs
bark", both inheriting the class 'Animals'. Now create an object for each of the subclasses and call their
respective methods.
Option
A) 10 20 ..
B) 20 10
C) 10 10
D) 20 20
11. Why non-static variable cannot be referenced from a static method in Java?
12. What will happen if we do not override all abstract methods in
subclass?
14. Why abstract class has constructor even though you cannot create
object?