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???
About Question enthuware.ocpjp.v17.2.3726 :
Moderator: admin
-
- Posts: 24
- Joined: Wed Sep 28, 2022 9:41 am
- Contact:
-
- Site Admin
- Posts: 10398
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v17.2.3726 :
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.
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.
Who is online
Users browsing this forum: No registered users and 1 guest