About Question enthuware.ocajp.i.v7.2.1405 :
Moderator: admin
-
- Posts: 15
- Joined: Tue Jan 13, 2015 12:10 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1405 :
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.
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1405 :
Execution does not stop after the first MyException is thrown. Why do you think so?
-Paul.
-Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 15
- Joined: Tue Jan 13, 2015 12:10 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1405 :
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!
-
- Posts: 1
- Joined: Fri Apr 10, 2015 6:05 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1405 :
Why is String[] args not counted as an object?
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1405 :
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.
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.
-
- Posts: 1
- Joined: Sat Jun 27, 2015 6:20 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1405 :
1. new MyException();
2.Noobs a = new Noobs(); 3. Noobs b = new Noobs();
3 objects are created ? where does the fourth come from ?
2.Noobs a = new Noobs(); 3. Noobs b = new Noobs();
3 objects are created ? where does the fourth come from ?
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1405 :
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.
-
- Posts: 12
- Joined: Wed Jul 15, 2015 4:05 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1405 :
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!
Oh well, if such a question occurs on the exam I know I should focus on the objects created by the code itself!
-
- Posts: 29
- Joined: Mon Mar 30, 2015 6:00 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1405 :
yeah, i included the args array too. do you think we should if this ever came up in the exam?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.
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1405 :
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.
-
- Posts: 1
- Joined: Sun May 08, 2016 11:20 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1405 :
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?
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?
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1405 :
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.
HTH,
Paul.
If you like our products and services, please help us by posting your review here.
-
- Posts: 8
- Joined: Thu Mar 24, 2016 12:02 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1405 :
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:
When new MyException is invoked, are there 2 objects created: MyException and Exception?
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();
}
}
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1405 :
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.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:When new MyException is invoked, are there 2 objects created: MyException and Exception?Code: Select all
class MyException extends Exception { MyException() { super(); } }
If you like our products and services, please help us by posting your review here.
-
- Posts: 8
- Joined: Thu Mar 24, 2016 12:02 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1405 :
Thank you for your help.
Now I understand.
Now I understand.
-
- Posts: 14
- Joined: Mon Jun 20, 2016 11:16 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1405 :
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?
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?
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1405 :
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.
-
- Posts: 14
- Joined: Mon Jun 20, 2016 11:16 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1405 :
Thanks a lot.I understood it clearly and the link was very helpful.
-
- Posts: 4
- Joined: Tue May 15, 2018 6:44 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1405 :
Hello admin
Why do you think String[] args shouldn't be considered?
secondly
What does this line in explanation of the answer means?
thanks
Nazia
Why do you think String[] args shouldn't be considered?
secondly
What does this line in explanation of the answer means?
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.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.
thanks
Nazia
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1405 :
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.
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.
-
- Posts: 4
- Joined: Tue May 15, 2018 6:44 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1405 :
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?
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?
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1405 :
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.
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.
-
- Posts: 1
- Joined: Thu Jan 02, 2020 5:27 am
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1405 :
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?
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?
-
- Site Admin
- Posts: 10036
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocajp.i.v7.2.1405 :
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.
Who is online
Users browsing this forum: No registered users and 53 guests