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
Alina_Lapina
Posts: 15
Joined: Tue Jan 13, 2015 12:10 pm
Contact:

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

Post by Alina_Lapina »

How come that 4 objects are created, when the execution stops after the first MyException it thrown? I thowhgt it was only 1 object created, because the first object named 'a' of Noobs type was not finished its creating process because of the exception.

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

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

Post by admin »

Execution does not stop after the first MyException is thrown. Why do you think so?
-Paul.
If you like our products and services, please help us by posting your review here.

Alina_Lapina
Posts: 15
Joined: Tue Jan 13, 2015 12:10 pm
Contact:

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

Post by Alina_Lapina »

I was wrong. Executions of all code examples in my textbook was stopped after en exception was thrown. I mean every time it was the last thing that happened. Now I understand. Thank you!

pillphil
Posts: 1
Joined: Fri Apr 10, 2015 6:05 am
Contact:

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

Post by pillphil »

Why is String[] args not counted as an object?

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

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

Post by admin »

You are right, you may count the String[] object referred to by args as well (although it is not created by the given code). Explanation has been updated to include this as well.

This is why the explanation notes that this question is ambiguous as it does not state precisely what objects should be included in the count.

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

jatin2086
Posts: 1
Joined: Sat Jun 27, 2015 6:20 am
Contact:

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

Post by jatin2086 »

1. new MyException();
2.Noobs a = new Noobs();        3. Noobs b = new Noobs();

3 objects are created ? where does the fourth come from ?

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

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

Post by admin »

Did you read the explanation? The first line explains why 4 objects are created. Two MyException objects are created.
If you like our products and services, please help us by posting your review here.

Vermeulen
Posts: 12
Joined: Wed Jul 15, 2015 4:05 pm
Contact:

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

Post by Vermeulen »

Like pillphill I counted the args array as well and answered 5. Indeed I was also wondering about Class objects, but forgot about Thread :).

Oh well, if such a question occurs on the exam I know I should focus on the objects created by the code itself!

NickWoodward
Posts: 29
Joined: Mon Mar 30, 2015 6:00 pm
Contact:

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

Post by NickWoodward »

admin wrote:You are right, you may count the String[] object referred to by args as well (although it is not created by the given code). Explanation has been updated to include this as well.

This is why the explanation notes that this question is ambiguous as it does not state precisely what objects should be included in the count.

HTH,
Paul.
yeah, i included the args array too. do you think we should if this ever came up in the exam?

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

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

Post by admin »

No, we do not think that the array object should be included here.
If you like our products and services, please help us by posting your review here.

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: 10036
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: 10036
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: 10036
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: 10036
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: 10036
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: 10036
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 70 guests