Win a copy of Pro Spring MVC with WebFlux: Web Development in Spring Framework 5 and Spring Boot 2 this week in the Spring forum!
  • 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
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

Question about Inheritance and InstanceOf method

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

The author of this question is Udayan Khattry taken from his Java Certification online course
 
Clemonte Johnstone
Ranch Hand
Posts: 110
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear all, please could you explain why the program produces the result that it does. Thank you in advance
 
Saloon Keeper
Posts: 12997
281
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please, first explain to us why you think B) is the correct answer. We can then help you find the mistake in your reasoning.
 
Clemonte Johnstone
Ranch Hand
Posts: 110
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Clemonte Johnstone wrote:Dear all, please could you explain why the program produces the result that it does. Thank you in advance



I am not sure how to approach solving this question, to be honest.
 
Clemonte Johnstone
Ranch Hand
Posts: 110
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stephan van Hulst wrote:Please, first explain to us why you think B) is the correct answer. We can then help you find the mistake in your reasoning.


I am not sure how to approach solving this question, to be honest.
 
Marshal
Posts: 72946
330
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does the book give you any explanation?

Print the code on a sheet of paper, with all the lines separated (treble‑spacing). Get a pencil and write the path of execution against each line. Write down wheter the predicate for each if is true or false.
 
Campbell Ritchie
Marshal
Posts: 72946
330
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By the way: instanceof is a keyword use as an operator, not a method.
 
Clemonte Johnstone
Ranch Hand
Posts: 110
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Does the book give you any explanation?

Print the code on a sheet of paper, with all the lines separated (treble‑spacing). Get a pencil and write the path of execution against each line. Write down wheter the predicate for each if is true or false.



No explanations provided
 
Clemonte Johnstone
Ranch Hand
Posts: 110
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Does the book give you any explanation?

Print the code on a sheet of paper, with all the lines separated (treble‑spacing). Get a pencil and write the path of execution against each line. Write down wheter the predicate for each if is true or false.



Did that.

Why is P not an instance of M?
 
Stephan van Hulst
Saloon Keeper
Posts: 12997
281
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You appear to interpret the lack of "P" in the output as an indication that P is not an instance of M. That's wrong. Let's take a look at the relevant lines.

The obj variable refers to an instance of O. "P" is only printed when the object referred to by obj is an instance of P. An O is not a P, so "P" is not printed.
 
Marshal
Posts: 26610
81
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Clemonte Johnstone wrote:No explanations provided



The online materials are trying to help you with questions about the instanceof operator, and they don't tell you anything about that operator? If that's the case then I would suggest finding some other source of help.

Or do the materials recommend some other source for you to do your research in?

But probably I'm misinterpreting. I expect there is information about instanceof there. No?

 
It means our mission is in jeapordy! Quick, read this tiny ad!
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic