About Question enthuware.ocajp.i.v8.2.1449 :

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

Moderator: admin

Post Reply
Antonio
Posts: 3
Joined: Tue May 15, 2018 2:54 am
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1449 :

Post by Antonio »

Thank you for quick response, Paul!

Unfortunately I'm still in the dark.

The two contradicting statements (summary) for me are following:
  • 1. Not every class belongs to a package (Test 2, Q: 47)
    2. Classes without defined package have automatically imported package with no name (default package) (Test 3, Q: 69)
Those lead me to following conclusions:
  • 1st statement means that classes without package doesn't belong to default package.
    2nd statement confirms that the fact that Java automatically imports default package means that the class belongs to the default package?
Could you please point out where my conclusions are wrong?

Thank you for help!

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

Re: About Question enthuware.ocajp.i.v8.2.1449 :

Post by admin »

Your question made me dig into the JLS and here is what I found -
1. Section 7.4.2 says, "A compilation unit that has no package declaration is part of an unnamed package."

So clearly, the statement "Not every class belongs to a package" in Qid 2.1449 (T2 Q47) is incorrect because JLS calls unnamed package a package. Must be fixed.

2. Further, section 7.3 and 7.5 say (respectively):
Every compilation unit implicitly imports every public type name declared in the predefined package java.lang , as if the declaration import java.lang.*; appeared at the beginning of each compilation unit immediately after any package statement. As a result, the names of all those types are available as simple names in every compilation unit.
and
Without the use of an appropriate import declaration, the only way to refer to a type declared in another package, or a static member of another type, is to use a fully qualified name


These two statements imply that classes of the same package are accessible to each other without any import statements.

So the statement in Qid 2.894 (T2 q69) is correct because all classes of the noname package can indeed access each other. The explanation in the question also states, "However, note that this default package cannot be imported in classes that belong to any other package at all, not even with any sort of import statement.", which is also correct.


In summary, I think the explanations to use the term "unnamed" package instead of "default" package because that is the terminology used by JLS. In other words, class that don't have a package statement belong to the "unnamed"
package.

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

Antonio
Posts: 3
Joined: Tue May 15, 2018 2:54 am
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1449 :

Post by Antonio »

Thanks a lot for you help and time, Paul.
Now it's clear.

swarna pakeer
Posts: 16
Joined: Thu Mar 19, 2020 2:27 pm
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1449 :

Post by swarna pakeer »

"Every class belongs to a package" , to which Object oriented feature of Java this belongs to ?

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

Re: About Question enthuware.ocajp.i.v8.2.1449 :

Post by admin »

It has nothing to do with OO. It is just a feature of java. The second alternate form of question is not good but is mentioned because of the reason explained there.
If you like our products and services, please help us by posting your review here.

Seán Kennedy
Posts: 12
Joined: Wed Feb 17, 2021 6:55 am
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1449 :

Post by Seán Kennedy »

Hi, the first option "Every class must have a main method so that it can be tested individually from command line." confuses me. The answer states "The main method is required only if you want to execute that class directly from a command line.". Fully agree that not every class needs a main() method but if you want to test it "individually from command line" as the question asks, you do, don't you? In other words, should this not be a correct option also i.e. if you want to test your class individually from the command line, you need a main() method. Thanks, Seán.

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

Re: About Question enthuware.ocajp.i.v8.2.1449 :

Post by admin »

It is really an ambiguous option, to be honest. The way I am interpreting "individually" is that the class is not part of a library or some other set of classes. Since "testing" does not mean executing the main method, "testing from command line" doesn't necessarily mean that that class is to be executed "directly". For example, a class's may have several business methods and that class still can be tested from command line using whatever testing methodology one might be using such as using JUnit. Further, executing the main method is no guarantee that its business methods are tested!

Overall, I guess if one selects this as a right option, it should be alright. It is a badly framed option.
If you like our products and services, please help us by posting your review here.

Seán Kennedy
Posts: 12
Joined: Wed Feb 17, 2021 6:55 am
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1449 :

Post by Seán Kennedy »

Thanks for that. Appreciate the prompt response. /Seán.

Post Reply

Who is online

Users browsing this forum: No registered users and 41 guests