Page 1 of 1

About Question enthuware.ocpjp.v8.2.1233 :

Posted: Mon Jul 11, 2016 12:53 pm
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.

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

Posted: Mon Jul 11, 2016 10:20 pm
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.

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

Posted: Wed Sep 07, 2016 6:45 am
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();

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

Posted: Wed Sep 07, 2016 9:09 am
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.

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

Posted: Sun May 21, 2017 3:11 pm
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?

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

Posted: Sun May 21, 2017 9:58 pm
by admin
Yes, that is correct.

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

Posted: Sun Apr 08, 2018 4:19 am
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();
?

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

Posted: Sun Apr 08, 2018 5:41 am
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.

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

Posted: Sat Aug 31, 2019 3:29 am
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.

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

Posted: Sat Aug 31, 2019 4:35 am
by admin
Thank you for your suggestion. Will improve the problem statement!