I have a pretty basic question about what I think would be inheritance.
If you have a class Person and a class Boy that is a subclass of A and you do something like:
Person fred = new Boy();
Is the fred object a person or is it a boy?
And would method calls that are overridden in the Boy class be called or would the methods in the Person class be called? I have been trying to figure this out for a while, and I can't seem to get it. If anyone can clarify how this works that would be great. And I'm learning in java if that makes a difference.
OOP Question
Started by orang, Mar 21 2009 07:31 AM
4 replies to this topic
#1
Posted 21 March 2009 - 07:31 AM
|
|
|
#2
Posted 21 March 2009 - 09:31 AM
The static type of fred would be Person and the dynamic type would be boy. Method selection at runtime is based on the dynamic type. So I'd probably go with the methods in boy. I learning java too! ;)
Perfection of means and confusion of ends seem to characterize our age. Albert Einstein :confused:
#3
Posted 21 March 2009 - 10:32 AM
#5
Posted 21 March 2009 - 11:07 AM
because boy is a sub class from person, this separation occurs when boy have diffrent variables and methods that arnt in person class and adding these variables and methods would effect the other types like "girl" or "mature"..etc.
in the same time theres certain attributes in person that will be used in the boy subclass
in the same time theres certain attributes in person that will be used in the boy subclass
yo homie i heard you like one-line codes so i put a one line code that evals a decrypted one line code that prints "i love one line codes"
eval(base64_decode("cHJpbnQgJ2kgbG92ZSBvbmUtbGluZSBjb2Rlcyc7"));
www.amrosama.com | the unholy methods of javascript


Sign In
Create Account

Back to top









