The S.O.P. can be read as "Use the n3 object's Network reference (the first p), to find that object's reference (n2), and use that object's reference (the second p) to find that object's (n1's) id, and print that id.
Roel De Nijs wrote:
Small note: you made a little typo in the signature of your main method. And although the code snippet compiles without any errors, you can't execute the program. Can you spot your typo?
John Lerry wrote:
Roel De Nijs wrote:
Small note: you made a little typo in the signature of your main method. And although the code snippet compiles without any errors, you can't execute the program. Can you spot your typo?
public static void main(String args[])
Mushfiq Mammadov wrote:Therefore I want to know that what is this in this case? new Network() ?
Mushfiq Mammadov wrote:Therefore I want to know that what is this in this case? new Network() ?
“You may never get to touch the Master, but you can tickle his creatures.”
― Thomas Pynchon, Gravity's Rainbow
Blake Edward wrote:Pencil and paper has been working great for me because I can build images and pictures that stick in my head and help me with other snippets.
Roel De Nijs wrote:Output: this=Network@55ca6954 n1=Network@55ca6954 n1.p=Network@55ca6954
Roel De Nijs wrote:
Mushfiq Mammadov wrote:Therefore I want to know that what is this in this case? new Network() ?
One veyr important rule to remember: besides a few exceptions, you always need the new keyword to create an instance. So just using this would never result in a new object.
Time for another pop quiz question! Can you list the few exceptions on the above rule (with an example)? I'm thinking of 4 very common ones (which you all need to know for the OCA exams). Ready, set, go!![]()
Mushfiq Mammadov wrote:Maybe I understand wrong again, if it happens please correct my mistakes
Roel De Nijs wrote: But there are some exceptions to this rule. And that's the pop quiz question: can you list the few exceptions on the above rule (with an example)? I'm thinking of 4 very common ones (which you all need to know for the OCA exams).
Roel De Nijs wrote:So now you should try to list the exceptions on this rule, meaning give some code examples which creates new objects without using the new keyword. And you are lucky, I'm in a generous mood. So I'll provide the first example:A new String object was created, but the new keyword is not required!
A tip to help you with these kind of questions is to look at how many times the keyword new is invoked. That number is the number of how many objects that are created But be careful: with autoboxing (as in line 3) the new invocation is done behind the scenes. But line 3 actually reads: Short story = new Short((short)200);. So in this example there are 4 invocations of keyword new, so 4 objects created and thus at most 4 objects which can be eligible for GC at line 16.
Mushfiq Mammadov wrote:Oh, sorry, the problem is that I understand "exceptions" as the topic Exception so I guessed such this question is about Exception.
Mushfiq Mammadov wrote:Please correct my mistake. Thanks in advance
Roel De Nijs wrote: I assumed the use of "exceptions" made you misunderstand the question. That's why I added an example the 2nd time so it would be crystal-clear
![]()
Roel De Nijs wrote: You are absolutely spot-on!
![]()
I have to say I'm happily surprised you were able to list all exceptions to the above rule. I didn't have expected you could list all of them. Have a cow for this great achievement!
Roel De Nijs wrote: 4/ declare an enum typeWithout using the new keyword, this code creates 7 Day instances/objects. Just to be clear: the objects/instances are created when you declare them (as in this code snippet). When you use one of the enum constants as in Days d = Days.FRIDAY; you are just using the reference variable, you are not creating an object/instance. So WEDNESDAY is actually a reference variable which is referring to a Day object/instance. This of course applies to all other enum constants as well
![]()
Roel De Nijs wrote: (Disclaimer: in Java 8 you can also create lambda expressions without using the new keyword)
Mushfiq Mammadov wrote:Is it possible to be a question about this in actual exam OCA SE 8? or this topic include in OCP exam?
Roel De Nijs wrote:(PS. I fixed the wrong name in the quote of my previous post. Thanks for reporting. That could be considered as a - small - mistake
)
A berm makes a great wind break. And we all like to break wind once in a while. Like this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|