• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Question on Enthuware Mock Tests 1Z0-809

 
Ranch Hand
Posts: 127
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Here is the question in Enthuware:-

What will the following code print when compiled and run?



This is printing "big data". However, answer specifies that "It will not print anything".

Thanks,
Raghu
 
Bartender
Posts: 2236
63
IntelliJ IDE Firefox Browser Spring Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It should print nothing. I just compiled and run this and I got no output.
 
Enthuware Software Support
Posts: 4646
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The following explanation is included with the question:


This question illustrates the fundamental aspect of overriding, which is that it is the actual class of object and not the class of the reference type that determines which instance method will be invoked.

Here, actual class of the object pointed to by w is GoodWidget and so GoodWidget's doWidgetStuff will be invoked. This method does nothing and so nothing is printed. Notice that the explicit cast to Widget has no impact because the class of the reference is not considered while invoking the instance methods at all.

But if you try to access the field (or a static method) directly, the class of the reference is used. Therefore,         


 
Bartender
Posts: 3788
40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Anilprem wrote:The following explanation is included with the question:


This question illustrates the fundamental aspect of overriding,




Hi Paul, I would say it illustrates polymorphism OOP principle, and sub-typing is a kind of polymorphism.

https://en.wikipedia.org/wiki/Polymorphism_%28computer_science%29

(besides that all is good )
 
Paul Anilprem
Enthuware Software Support
Posts: 4646
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mikalai Zaikin wrote:

Paul Anilprem wrote:The following explanation is included with the question:


This question illustrates the fundamental aspect of overriding,




Hi Paul, I would say it illustrates polymorphism OOP principle, and sub-typing is a kind of polymorphism.

https://en.wikipedia.org/wiki/Polymorphism_%28computer_science%29

(besides that all is good )


Hi Mikalai,
Thank you for your feedback. It is true that it illustrates polymorphism. But then it is also true that it illustrates OOP and that it illustrates Java programming.
But the most specific thing that it illustrates is the behavior that you get when you override a method. That is why the explanation mentions overriding instead of other broader concepts.

Another way to look at it is that the link that you quoted mentions multiple ways of achieving polymorphism. This code does not illustrate them all. So to say that this code illustrates polymorphism would be correct but too vague.

HTH,
Paul.
 
If tomatoes are a fruit, then ketchup must be a jam. Taste this tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic