class Feline {
public String type = "f ";
public Feline() {
System.out.print("feline ");
}
}
public class Cougar extends Feline {
public Cougar() {
System.out.print("cougar ");
}
public static void main(String[] args) {
new Cougar().go();
}
void go() {
type = "c ";
System.out.print(this.type + super.type);
}
}
What is the result?
A) cougar c c
B) cougar c f
C) feline cougar c c
D) feline cougar c f
E) Compilation fails
F) An exception is thrown at run time.
According to sample questions the correct answer is option c
but i feel the answer should be option d... because super.type = f and not c..
If i change the local variable type in go() to instance variable . the output will be "feline cougar c f"... if i don't change it the output will be " feline cougar c c"... but what i don't understand is the output says "S.O.P(this.type+super.type); So how did it print c since we cannot use "this" on local variables!