About Question enthuware.ocpjp.v17.2.3726 :

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

Moderator: admin

Post Reply
edufin166@yahoo.com
Posts: 24
Joined: Wed Sep 28, 2022 9:41 am
Contact:

About Question enthuware.ocpjp.v17.2.3726 :

Post by edufin166@yahoo.com »

In this question we have:

class A extends Base{
@Override
int power(){ // Class A method power returning "0"
return 0;
}
}

if(base instanceof A a && a.power() == 1 ){     //
((AA)a).mAA();
}      

In the IF above...
How can I have "a.power() == 1" in the If-Conditional above as TRUE, and therefore entering in the conditional and executing ((AA)a).mAA(),
if in the "Class A" the method power return 0???

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

Re: About Question enthuware.ocpjp.v17.2.3726 :

Post by admin »

Right, so a.power() == 1 will be false. The control won't enter the if block and ((AA)a).mAA(); won't be executed.
But what is the issue? It is still valid code. It is also possible that a may point to an instance of AA, which return 1.

Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests