About Question enthuware.ocajp.i.v7.2.1315 :
Moderator: admin
About Question enthuware.ocajp.i.v7.2.1315 :
Hi,
Regarding nested class, are they part of the OCAJP? I thought they were not included but instead they were part of the OCPJP exam.
Regarding nested class, are they part of the OCAJP? I thought they were not included but instead they were part of the OCPJP exam.
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1315 :
They are not explicitly mentioned but some students have reported getting a question on it. So better to know the basics than to be surprised in the exam.
-
- Posts: 25
- Joined: Thu Jan 10, 2013 8:45 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1315 :
I don't understand why int i isn't accessible from perform_work(); if it's not declared as final.
What rule/logic is at play here?
What rule/logic is at play here?
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1315 :
The rule is that if you want to access a method parameter in an inner class defined in that method, the parameter must be final.Ambiorix wrote:I don't understand why int i isn't accessible from perform_work(); if it's not declared as final.
What rule/logic is at play here?
-
- Posts: 37
- Joined: Thu Feb 13, 2014 12:58 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1315 :
Would you please help me to understand this?admin wrote:The rule is that if you want to access a method parameter in an inner class defined in that method, the parameter must be final.Ambiorix wrote:I don't understand why int i isn't accessible from perform_work(); if it's not declared as final.
What rule/logic is at play here?
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1315 :
Code: Select all
public class TestClass {
public static void main(final String[] args) {
class Inner{
void m(){
System.out.println(args); //this will work ONLY if args is final
}
}
new Inner().m();
}
}
-
- Posts: 37
- Joined: Thu Feb 13, 2014 12:58 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1315 :
admin wrote:Code: Select all
public class TestClass { public static void main(final String[] args) { class Inner{ void m(){ System.out.println(args); //this will work ONLY if args is final } } new Inner().m(); } }
thank you.
What is the logic?
-
- Site Admin
- Posts: 10388
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1315 :
JLS hasn't elaborated on the rule. You may go through section 8.1.3 though: http://docs.oracle.com/javase/specs/jls ... ml#d5e9405
Who is online
Users browsing this forum: No registered users and 4 guests