Page 1 of 1
About Question enthuware.ocajp.i.v7.2.1136 :
Posted: Mon Oct 29, 2012 9:36 am
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
Re: About Question enthuware.ocajp.i.v7.2.1136 :
Posted: Mon Oct 29, 2012 12:22 pm
by admin
The option says, "(b instanceof A) will return false". That is why it is the wrong option.
HTH,
Paul.
Re: About Question enthuware.ocajp.i.v7.2.1136 :
Posted: Sat Jan 18, 2014 9:13 am
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?
Re: About Question enthuware.ocajp.i.v7.2.1136 :
Posted: Sat Jan 18, 2014 9:24 am
by admin
Did you try it out?
It is true because b extends A and A implements T2.
HTH,
Paul.
Re: About Question enthuware.ocajp.i.v7.2.1136 :
Posted: Sat Jan 18, 2014 11:57 am
by Kipchakbaev
Well, I just ran it, and (b instanceof T2) returned true
I studied hard, but this question caught me.
Thank you Paul!
Enthuware is really useful.
Re: About Question enthuware.ocajp.i.v7.2.1136 :
Posted: Sat Feb 25, 2017 11:50 am
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.
Re: About Question enthuware.ocajp.i.v7.2.1136 :
Posted: Sat Feb 25, 2017 11:59 am
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.