About Question enthuware.ocpjp.v8.2.1233 :

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

Moderator: admin

Post Reply
Ismaelspk
Posts: 3
Joined: Thu Jun 23, 2016 8:23 am
Contact:

About Question enthuware.ocpjp.v8.2.1233 :

Post by Ismaelspk »

Which of the given options if put at //1 will correctly instantiate objects of various classes defined in the following code?

Code: Select all

public class TestClass
{
   public class A
   {
   }
   public static class B
   {
   }
   public void useClasses()
   {
      //1
   }
}
a. new TestClass().new A()
b. new TestClass.B();
c. new A();
d. new TestClass.A();
e. All of these are valid.

I marked option a by the statement "correctly instantiate objects of various classes". wrong interpretation ? Because the only one that make various object instances is in option a.

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

Re: About Question enthuware.ocpjp.v8.2.1233 :

Post by admin »

There are multiple classes in the given code. You are asked to create objects of these classes but not necessarily all classes in the same option.

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

ramy6_1
Posts: 124
Joined: Wed Feb 12, 2014 2:44 am
Contact:

Re: About Question enthuware.ocpjp.v8.2.1233 :

Post by ramy6_1 »

Hello ,

Why new TestClass.A(); should work here , it is a static nested inner class syntax but A is not a static ?
It is a bit confused that both below syntax works while B is static and A is not

new TestClass.B();
new TestClass.A();

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

Re: About Question enthuware.ocpjp.v8.2.1233 :

Post by admin »

The code new TestClass.A() is within an instance method of class TestClass. Therefore, there is already an instance of TestClass associated with the method (i.e. "this" ). That is why, even though A is not static, new TestClass.A() is valid inside the given method.
If you like our products and services, please help us by posting your review here.

lenalena
Posts: 56
Joined: Tue Feb 21, 2017 4:24 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1233 :

Post by lenalena »

Question enthuware.ocpjp.v8.2.1382 has a statement in the explanation that states
tc.new Runner() is a valid construct because Runner is a non-static inner class. So you cannot do 'new TestClass.Runner()'.
Is it because in that question it's the static main method that does the object creation? And there is no reference to "this" in static main?

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

Re: About Question enthuware.ocpjp.v8.2.1233 :

Post by admin »

Yes, that is correct.
If you like our products and services, please help us by posting your review here.

thodoris.bais
Posts: 25
Joined: Sat Jun 03, 2017 4:56 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1233 :

Post by thodoris.bais »

I cannot really understand the syntax:

Code: Select all

new TestClass.A();
Why isn't it

Code: Select all

new TestClass().A();
?

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

Re: About Question enthuware.ocpjp.v8.2.1233 :

Post by admin »

new TestClass() is the syntax of creating a TestClass object. So new TestClass().A(); will be same as invoking a method named A on the newly created TestClass object. But you know that there is no method named A in TestClass.
If you like our products and services, please help us by posting your review here.

marcioggs
Posts: 10
Joined: Sat Aug 31, 2019 3:19 am
Contact:

Re: About Question enthuware.ocpjp.v8.2.1233 :

Post by marcioggs »

Agree with the OP.

The text says that the option chosen must instantiate objects of various classes.
B, C and D instantiates objects of only one class, not various.
A is the only answer that instantiates objects of more than one class (TestClass and A).

The question text should be changed to something different not to be ambiguous, like:
"Which of the given options could be inserted at //1 in order to compile".
That´s what this question is about.

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

Re: About Question enthuware.ocpjp.v8.2.1233 :

Post by admin »

Thank you for your suggestion. Will improve the problem statement!
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 28 guests