About Question enthuware.ocpjp.v8.2.1492 :

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

Moderator: admin

Post Reply
ramy6_1
Posts: 124
Joined: Wed Feb 12, 2014 2:44 am
Contact:

About Question enthuware.ocpjp.v8.2.1492 :

Post by ramy6_1 »

Hello ,

Not sure what is meant by 'package member classes'.

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

Re: About Question enthuware.ocpjp.v8.2.1492 :

Post by admin »

A class that is a member of a package as opposed to a member of a class.
If you like our products and services, please help us by posting your review here.

jamesfeng2
Posts: 2
Joined: Wed Oct 26, 2016 8:02 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1492 :

Post by jamesfeng2 »

why below can be compiled and print hello?
That against "the modifier static pertains only to member classes, not to top level or local or anonymous classes."

package p2;

abstract class cd76 {

public static void main(String[] args) {
System.out.println("hello");

}
}

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

Re: About Question enthuware.ocpjp.v8.2.1492 :

Post by admin »

The main method is a static method. An instance of the class cd76 is not required to run it. Also, the main method is not creating any instance of class cd76. So there is no reason for it to not compile and run.
Why do you think it should not compile and run?
-Paul.
If you like our products and services, please help us by posting your review here.

runnerdave
Posts: 12
Joined: Mon Jan 30, 2017 2:58 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1492 :

Post by runnerdave »

one of the options is:
Anonymous classes cannot be declared static.

that is true as well, how could I know which ones to mark then?

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

Re: About Question enthuware.ocpjp.v8.2.1492 :

Post by admin »

runnerdave wrote:one of the options is:
Anonymous classes cannot be declared static.

that is true as well, how could I know which ones to mark then?
You have to select 2 correct options and this is one of the 2 correct options. So you should select option 2 and 4.
If you like our products and services, please help us by posting your review here.

__JJ__
Posts: 125
Joined: Thu Jul 05, 2018 6:44 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1492 :

Post by __JJ__ »

admin wrote:
Mon Sep 19, 2016 10:20 am
A class that is a member of a package as opposed to a member of a class.
So, are the terms "package member class" and "top-level class" synonymous?

TIA.

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

Re: About Question enthuware.ocpjp.v8.2.1492 :

Post by admin »

Yes, as per Section 7.1 of JLS:
The members of a package are its subpackages and all the top level class types (§7.6, §8 (Classes)) and top level interface types (§9 (Interfaces)) declared in all the compilation units of the package.
If you like our products and services, please help us by posting your review here.

__JJ__
Posts: 125
Joined: Thu Jul 05, 2018 6:44 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1492 :

Post by __JJ__ »

Hi Admin
I'm just going over some notes and I found this note that I made a few days ago:
Anonymous classes cannot be declared static.
which got me thinking

Code: Select all

class T29 {   
    static Runnable r = new Runnable(){ 
        public void run(){}
    };
}
In what way is this not an anonymous class, and a static one at that? My understanding is that an anonymous class is a class definition combined with instantiation.
Thank you very much.

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

Re: About Question enthuware.ocpjp.v8.2.1492 :

Post by admin »

The variable r is static. Not the anonymous class.
If you like our products and services, please help us by posting your review here.

__JJ__
Posts: 125
Joined: Thu Jul 05, 2018 6:44 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1492 :

Post by __JJ__ »

admin wrote:
Thu Jul 26, 2018 9:40 am
Yes, as per Section 7.1 of JLS:
The members of a package are its subpackages and all the top level class types (§7.6, §8 (Classes)) and top level interface types (§9 (Interfaces)) declared in all the compilation units of the package.
OK, thank you.

__JJ__
Posts: 125
Joined: Thu Jul 05, 2018 6:44 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1492 :

Post by __JJ__ »

admin wrote:
Thu Aug 02, 2018 8:51 pm
The variable r is static. Not the anonymous class.
Yes of course. But...I don't see then what else there is to try to declare static. There's nothing to an anonymous class apart from

Code: Select all

Runnable r = new Runnable(){...} 
The only conceivable place (other than where I used it) that one could use the static keyword is before "new" which would be .. weird.

Code: Select all

Thread t = new Thread(static new Runnable(){...}); 
Anyway, I will remember that ACs cannot be declared static.
Thank you.

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

Re: About Question enthuware.ocpjp.v8.2.1492 :

Post by admin »

That is why it is not static. You can use javap to inspect the class file created for the anonymous class. Create a named static nested class and use javap on that to compare.
If you like our products and services, please help us by posting your review here.

__JJ__
Posts: 125
Joined: Thu Jul 05, 2018 6:44 pm
Contact:

Re: About Question enthuware.ocpjp.v8.2.1492 :

Post by __JJ__ »

admin wrote:
Thu Aug 02, 2018 11:44 pm
That is why it is not static. You can use javap to inspect the class file created for the anonymous class. Create a named static nested class and use javap on that to compare.
I'll try that, thanks very much.

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

Re: About Question enthuware.ocpjp.v8.2.1492 :

Post by admin »

Post by sreeharshitha » Fri Sep 13, 2019 12:50 am

if package member classes and top level classes are synonymous, why isn't option 1 correct?
If you like our products and services, please help us by posting your review here.

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

Re: About Question enthuware.ocpjp.v8.2.1492 :

Post by admin »

Option 1 says, "Package member classes can be declared static." But they can't be. That is why it is an incorrect option.

(Sorry, your original post got deleted by mistake. So, I recreated it.)
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 28 guests