Consider the following classes, declared in separate source files:
1. public class Base { 2. public void method(int i) { 3. System.out.print("Value is " + i+" "); 4. } // w ww.java 2 s. c o m 5. } 1. public class Sub extends Base { 2. public void method(int j) { 3. System.out.print("This value is " + j+" "); 4. } 5. public void method(String s) { 6. System.out.print("I was passed " + s+" "); 7. } 8. public static void main(String args[]) { 9. Base b1 = new Base(); 10. Base b2 = new Sub(); 11. b1.method(5); 12. b2.method(6); 13. } 14. }
What output results when the main method of the class Sub is run?
C.
The first message is produced by the Base class when b1.method(5) is called and is therefore Value is 5.
variable b2 is declared in the Base class.