Sample Questions

Moderator: admin

Post Reply
deepa.patre
Posts: 15
Joined: Thu Dec 13, 2012 9:44 am
Contact:

Sample Questions

Post by deepa.patre » Mon Jun 10, 2013 3:47 pm

Code: Select all

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..

Please advise!

admin
Site Admin
Posts: 8186
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: Sample Questions

Post by admin » Mon Jun 10, 2013 4:27 pm

Please quote the link from where you got it.
If you like our products and services, please help us by posting your review here.

deepa.patre
Posts: 15
Joined: Thu Dec 13, 2012 9:44 am
Contact:

Re: Sample Questions

Post by deepa.patre » Tue Jul 02, 2013 8:47 am

I got this code from OCAJP 7 sample questions. Here is the link : http://education.oracle.com/pls/web_pro ... =SQ1Z0_803

deepa.patre
Posts: 15
Joined: Thu Dec 13, 2012 9:44 am
Contact:

Re: Sample Questions

Post by deepa.patre » Tue Jul 02, 2013 8:54 am

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!

Please reply

Post Reply

Who is online

Users browsing this forum: No registered users and 12 guests