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

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

Moderator: admin

Post Reply
jihedamine
Posts: 1
Joined: Sun May 08, 2016 11:20 am
Contact:

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

Post by jihedamine »

The solution states "If you consider the String[] object referred to by args, the answer would then be 8."
Shouldn't it be 7 (6 +1) and not (6+2) as public static void main(String[] args) is created only once for the Noobs class?

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

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

Post by admin »

One is the empty String array object and one is the class object for String[]. But again, you should ignore such objects because we do not believe that is the intention of the question.

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

wuqing1450
Posts: 8
Joined: Thu Mar 24, 2016 12:02 pm
Contact:

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

Post by wuqing1450 »

My answer is 6: 2 Noobs; 2 MyException; 2 Exception objects?

My understanding of this case is that a default constructor will be written by JVM as below, since MyException doesn't have a constructor:

Code: Select all

class MyException extends Exception {
        MyException() {
                 super();
        }
}
When new MyException is invoked, are there 2 objects created: MyException and Exception?

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

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

Post by admin »

wuqing1450 wrote:My answer is 6: 2 Noobs; 2 MyException; 2 Exception objects?

My understanding of this case is that a default constructor will be written by JVM as below, since MyException doesn't have a constructor:

Code: Select all

class MyException extends Exception {
        MyException() {
                 super();
        }
}
When new MyException is invoked, are there 2 objects created: MyException and Exception?
That is not correct. Think of it like this. Let us says Apple extends Fruit. When you create an Apple object, do you create two objects? No. Apple is-a Fruit but that doesn't mean there are two independent objects created. The same Apple object is counted as an Apple object as well as Fruit object.
If you like our products and services, please help us by posting your review here.

wuqing1450
Posts: 8
Joined: Thu Mar 24, 2016 12:02 pm
Contact:

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

Post by wuqing1450 »

Thank you for your help. :)

Now I understand.

Sai Divya sree
Posts: 14
Joined: Mon Jun 20, 2016 11:16 pm
Contact:

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

Post by Sai Divya sree »

Hi,
i understood how four objects are created.i.e one noobs and its Myexception and again one noobs and its Myexception are created.But in the explanation it says two class objects(one for noobs and one for Myexception are created.that is totally (4+2) 6 are created.I couldn't understand how those other two objects come from?

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

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

Post by admin »

For every class that is loaded by the JVM, an object of a class named Class is created. You can read about it here: https://docs.oracle.com/javase/7/docs/a ... Class.html
If you like our products and services, please help us by posting your review here.

Sai Divya sree
Posts: 14
Joined: Mon Jun 20, 2016 11:16 pm
Contact:

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

Post by Sai Divya sree »

Thanks a lot.I understood it clearly and the link was very helpful.

naziat
Posts: 4
Joined: Tue May 15, 2018 6:44 am
Contact:

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

Post by naziat »

Hello admin
Why do you think String[] args shouldn't be considered?

secondly
What does this line in explanation of the answer means?
The question is ambiguous because two Class objects (one for Noobs and one for MyException) are also created. If you consider those, then the answer would be 6.
My question is, how can it be 6? What I have observed is Whenever Noobs object is created, it creates the MyException object as well, since there are 2 Noobs objects created explicitly, so there should be 4 objects created. But explanation says 6(if we consider Noobs+MyException), please advise.

thanks
Nazia

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

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

Post by admin »

1. Yes, the String array object pointed to by args can also be considered. That is why the explanation states that it is an ambiguous question because the problem statement does not clearly mention whether it is talking only about the objects created by the code in the main method or other objects as well. It also says that in our opinion only the objects directly created by the given code should be considered to arrive at the answer. From this perspective, the answer should be 4.

2. Answer will be 6 if you consider the two Class objects also. Please read my reply above. If you consider the String[] object, then the answer will be 7.

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

naziat
Posts: 4
Joined: Tue May 15, 2018 6:44 am
Contact:

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

Post by naziat »

Again my question remains unanswered.

According to my understanding, there will be 4 objects (excluding String[] args)
1) One object created for first Noobs object
2) Second object created of MyException by above first Noobs object
3) Third object created for second Noobs object
4) Fourth object created of MyException by above second Noobs object

But what makes you say that its 6 objects actually?

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

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

Post by admin »

That is what the first line of the explanation also says, "When a Noobs object is created, a MyException object is also created. Therefore a total of 4 objects are created. "

Regarding 6 objects, did you read my reply above (to Sai Diyva Sri)? It contains a link. You need to read that article to understand that 2 class objects are also created. That makes it 4+2 = 6 objects. But that is not required for the OCAJP exam.
If you like our products and services, please help us by posting your review here.

patricklm
Posts: 1
Joined: Thu Jan 02, 2020 5:27 am
Contact:

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

Post by patricklm »

Debugging this question on IntelliJ shows the following objects being created in the following order:
1) Noobs@792
2) MyException@7954
3) String[0]@795
4) Noobs@796
5) MyException@797

Does this question exclude the String[], the main method argument?

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

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

Post by admin »

Please check the explanation shown for this question. It explains the point that you have raised:
Note: Some candidates have reported getting a similar question.
The question is ambiguous because two Class objects (one for Noobs and one for MyException) are also created. If you consider those, then the answer would be 6. A String array object pointed to by args is also created and if you consider that, the answer would by 7. Further, several Thread objects are also created (although not directly by this code.) Since this is out of scope for the exam, it is best to ignore these kind of objects and consider only the objects created directly by the code.
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 30 guests