A good answer might be:
| |
Arrays of ObjectSince every class is a descendant of Object, an Object reference variable can be used with an object of any class. For example:
Each of the last three statements is correct (although in this program, useless.) It would not be correct if this followed the above statements: It is true that obj refers to a YouthBirthday object, which has a greeting() method. But the compiler needs to be told this with a type cast. The following is OK:obj.greeting(); A typecast is used to tell the compiler what is "really" in a variable that itself is not specific enough.To avoid such complications, always use reference variables that are as specific as possible.((YouthBirthday)obj).greeting(); | |
QUESTION 16:Is the following OK? Click Here after you have answered the questionObject obj; String str = "Yertle" ; obj = str; ((YouthBirthday)obj).greeting(); |