About Question enthuware.ocpjp.v8.2.1492 :
Moderator: admin
-
- Posts: 124
- Joined: Wed Feb 12, 2014 2:44 am
- Contact:
About Question enthuware.ocpjp.v8.2.1492 :
Hello ,
Not sure what is meant by 'package member classes'.
Not sure what is meant by 'package member classes'.
-
- Site Admin
- Posts: 10103
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1492 :
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.
-
- Posts: 2
- Joined: Wed Oct 26, 2016 8:02 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1492 :
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");
}
}
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");
}
}
-
- Site Admin
- Posts: 10103
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1492 :
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.
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.
-
- Posts: 12
- Joined: Mon Jan 30, 2017 2:58 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1492 :
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?
Anonymous classes cannot be declared static.
that is true as well, how could I know which ones to mark then?
-
- Site Admin
- Posts: 10103
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1492 :
You have to select 2 correct options and this is one of the 2 correct options. So you should select option 2 and 4.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?
If you like our products and services, please help us by posting your review here.
-
- Posts: 125
- Joined: Thu Jul 05, 2018 6:44 pm
- Contact:
-
- Site Admin
- Posts: 10103
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1492 :
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.
-
- Posts: 125
- Joined: Thu Jul 05, 2018 6:44 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1492 :
Hi Admin
I'm just going over some notes and I found this note that I made a few days ago:
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.
I'm just going over some notes and I found this note that I made a few days ago:
which got me thinkingAnonymous classes cannot be declared static.
Code: Select all
class T29 {
static Runnable r = new Runnable(){
public void run(){}
};
}
Thank you very much.
-
- Site Admin
- Posts: 10103
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1492 :
The variable r is static. Not the anonymous class.
If you like our products and services, please help us by posting your review here.
-
- Posts: 125
- Joined: Thu Jul 05, 2018 6:44 pm
- Contact:
-
- Posts: 125
- Joined: Thu Jul 05, 2018 6:44 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1492 :
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(){...}
Code: Select all
Thread t = new Thread(static new Runnable(){...});
Thank you.
-
- Site Admin
- Posts: 10103
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1492 :
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.
-
- Posts: 125
- Joined: Thu Jul 05, 2018 6:44 pm
- Contact:
-
- Site Admin
- Posts: 10103
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1492 :
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 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.
-
- Site Admin
- Posts: 10103
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question enthuware.ocpjp.v8.2.1492 :
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.)
(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.
Who is online
Users browsing this forum: No registered users and 25 guests