About Question enthuware.ocajp.i.v7.2.1136 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

Post Reply
ETS User

About Question enthuware.ocajp.i.v7.2.1136 :

Post by ETS User »

I coded this example up and tested it out...

Code: Select all

System.out.println(b instanceof A);
prints "true"...

though this was marked as an incorrect answer.

Please advise.

-- Robert

admin
Site Admin
Posts: 10046
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1136 :

Post by admin »

The option says, "(b instanceof A) will return false". That is why it is the wrong option.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

Kipchakbaev
Posts: 7
Joined: Sat Jan 18, 2014 8:04 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1136 :

Post by Kipchakbaev »

Code: Select all

class TestClass{    
     public static void main(String[] args){       
          A a = new A();       
          B b = new B();    
     }; 
} 
class A implements T1, T2{} 
class B extends A implements T1{} 
interface T1 { } 
interface T2 { }
How is it possible that
(b instanceof T2) will return true.
is a correct statement?

admin
Site Admin
Posts: 10046
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1136 :

Post by admin »

Did you try it out?

It is true because b extends A and A implements T2.

HTH,
Paul.
If you like our products and services, please help us by posting your review here.

Kipchakbaev
Posts: 7
Joined: Sat Jan 18, 2014 8:04 am
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1136 :

Post by Kipchakbaev »

Well, I just ran it, and (b instanceof T2) returned true :D
I studied hard, but this question caught me.

Thank you Paul!
Enthuware is really useful.

AndaRO
Posts: 31
Joined: Wed Feb 08, 2017 5:42 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1136 :

Post by AndaRO »

It's about to be transitive.
If b instanceof A return true and a instanceof T2 return true means that b instanceof T2 return true?

Please say me if I am correct.

admin
Site Admin
Posts: 10046
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v7.2.1136 :

Post by admin »

Please post complete code so that it is clear what you are asking. Also, please post what was the result of compilation and execution of your code.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 74 guests