A. The code will print 10 and 40 if // 3 is commented.
B. The code will print 40 if // 2 and // 3 are commented.
C. The code will not compile because of // 1.
D. The code will compile if the line marked // 2 is commented out.
E. None of these.
Class Heirarchy | Sub-classing | IS-A Relationship |
---|---|---|
Class A | sub-class of Object | A is-a Object,A's only parent is object |
Class B | sub-class of A | B is a A but A is-a Object =>B is a Object,B's only parent is A |
Class C | sub-class of B | C is a B but B is-a A =>C is a A & A is a Object => C is a object,C's only parent is B |
this is incorrect,c only inherits its super class B member(though it cannot inherit B's private member acc. to the inheritance rule).Jason Attin wrote:surely C inherits A's i
Try to enjoy your work while doing it,it will Automatically convert in Hard Work...
Please QuoteYourSources.
Jason Attin wrote:
1)Usually if you go up the hierarchy, say you want to access from a subclass variables or methods of a superclass you don't need to cast because if A is superclass of B then B is A. But you need to cast if you go down the hierarchy, correct?
i am not pretty sure what you intended to say but it is not possible to perform a cast down the heirarchy.for-ex-Jason Attin wrote:1)Usually if you go up the hierarchy, say you want to access from a subclass variables or methods of a superclass you don't need to cast because if A is superclass of B then B is A. But you need to cast if you go down the hierarchy, correct?
Jason Attin wrote:2)In a slightly different scenario, say we have again superclass A, subclass B extending A and subclass C extending B, and let's say that all the variables are all coderanch, then all the members in A are also inherited by B and by C, so C effectively has members in A. Correct?
Try to enjoy your work while doing it,it will Automatically convert in Hard Work...
Don't get me started about those stupid light bulbs. |