Sample Questions

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

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

Sample Questions

Post by deepa.patre »

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: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: Sample Questions

Post by admin »

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 »

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 »

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 46 guests