About Question enthuware.ocpjp.v7.2.1369 :

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

Moderator: admin

Post Reply
Harvey Manfrenjensen
Posts: 14
Joined: Fri May 11, 2018 6:59 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1369 :

Post by Harvey Manfrenjensen »

>>>Observe that there is no way doA() can be accessed.
fyi...

Code: Select all

class TopClass
{
    public Inner inner1 = new Inner()
    {
        public Inner doA(){  
            System.out.println("doing A"); 
            return this;
        }
    }.doA();  // call doA() here

    public void doA() { inner1.doA(); }
}

class Inner
{
   int value;
}

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

Re: About Question enthuware.ocpjp.v7.2.1369 :

Post by admin »

Assuming that you are trying to show a counter example, have you even tried to compile your code?
If you like our products and services, please help us by posting your review here.

Harvey Manfrenjensen
Posts: 14
Joined: Fri May 11, 2018 6:59 am
Contact:

Re: About Question enthuware.ocpjp.v7.2.1369 :

Post by Harvey Manfrenjensen »

you are right, it does not compile, i took it from the explanation of question,
which show inappropriate call of a new method of anonymous class.
Here is example, that compiles.

Regards, Paul

Code: Select all

class TopClass
{
    public Inner inner1 = new Inner()
    {
        public Inner doA(){  
            System.out.println("doing A"); 
            return this;
        }
    }.doA();  // call doA() here
}

class Inner
{
   int value;
}

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

Re: About Question enthuware.ocpjp.v7.2.1369 :

Post by admin »

Yes, this compiles but this is not the doA() that is given in the problem statement.

Your code does show an interesting way to invoke a method of an inner class though.

regards,
Paul.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 39 guests