Polymorphism Question
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
output:
super
sub display
Integer
sub
how in the above code the A class constructor gets called ?
the first statment of constructor should be call to this or super,if neither of them are explicitly put the compiler implictly calls super()
so,there should be no call to super as in the above code
OCPJP 6.0 93%
OCPJWCD 5.0 98%
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
mohitkumar gupta wrote:the first statment of constructor should be call to this or super,if neither of them are explicitly put the compiler implictly calls super()
The B() constructor calls B(int). Since that doesn't have a this or super call in it, then as you've just quoted above the compiler implicitly calls super().
A super-class constructor will always be called, one way or another.
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
mohitkumar gupta wrote:
how in the above code the A class constructor gets called ?
the first statment of constructor should be call to this or super,if neither of them are explicitly put the compiler implictly calls super()
so,there should be no call to super as in the above code
What about int - argument constructor?
BTW, Your topic and question seems to be different? And have look on the disp() method of your sub class~! If both are doing same operation, then you can't identify which one get called!~ Change it, and then check it.
|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
By the way, I think you have a mistake in your code. The superclass method disp() should print something like "super display". Then you will see that the constructor of A class is also aware of the polimorphism and will call the B.disp();
Edit: Gosh, Abimaran you were 7 seconds faster :-)
Cheers!
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Pedro Kowalski wrote:
Edit: Gosh, Abimaran you were 7 seconds faster :-)
Cheers!
Not that all!
|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
is equal to this
SCJP6.0,My blog Ranchers from Delhi
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
SCJP6.0,My blog Ranchers from Delhi
| I'm not dead! I feel happy! I'd like to go for a walk! I'll even read a tiny ad: The new gardening playing cards kickstarter is now live! https://www.kickstarter.com/projects/paulwheaton/garden-cards |








