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

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

Moderator: admin

Post Reply
The_Nick

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

Post by The_Nick »

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.

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

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

Post by admin »

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.

Ambiorix
Posts: 25
Joined: Thu Jan 10, 2013 8:45 am
Contact:

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

Post by Ambiorix »

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?

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

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

Post by admin »

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?
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.

fasty23
Posts: 37
Joined: Thu Feb 13, 2014 12:58 am
Contact:

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

Post by fasty23 »

admin wrote:
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?
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.
Would you please help me to understand this?

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

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

Post by admin »

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();
    }
}


fasty23
Posts: 37
Joined: Thu Feb 13, 2014 12:58 am
Contact:

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

Post by fasty23 »

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?

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

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

Post by admin »

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

Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests