About Question com.enthuware.ets.scjp.v6.2.456:

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

Moderator: admin

Post Reply
devlam
Posts: 50
Joined: Sun Nov 10, 2013 4:39 am
Contact:

About Question com.enthuware.ets.scjp.v6.2.456:

Post by devlam »

What is exactly a top-level class. I've searched on the internet and from that top-level classes are classes which are not innerclasses.
But someone also stating that static class members (so static String string = new String()) are also top-level classes.
I didn't find definitions where I could judge that as right or wrong.

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

Re: About Question com.enthuware.ets.scjp.v6.2.456 :

Post by admin »

You may check this out: http://docs.oracle.com/javase/specs/jls ... jls-8.html

It explains all the terms.

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

zidian
Posts: 1
Joined: Fri Jun 20, 2014 3:36 pm
Contact:

Re: About Question com.enthuware.ets.scjp.v6.2.456 :

Post by zidian »

Can you explain what a "package member class" means? I checked the link you provided and nothing is described in that manner.

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

Re: About Question com.enthuware.ets.scjp.v6.2.456 :

Post by admin »

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

TwistedLizard
Posts: 57
Joined: Sat Mar 01, 2014 1:48 pm
Contact:

Re: About Question com.enthuware.ets.scjp.v6.2.456 :

Post by TwistedLizard »

admin wrote:You may check this out: http://docs.oracle.com/javase/specs/jls ... jls-8.html
The 2nd & 3rd sentences on that page state:
A top level class is a class that is not a nested class.
A nested class is any class whose declaration occurs within the body of another class or interface.
In this code therefore, as its declaration occurs within the body of Test, Inner1 is a nested class, not a top level class.

Code: Select all

class Test{
  static class Inner1{
    static class S1{           //ok
      static class s2{}        //ok
    }      
  }
  class Inner2{
   // static class S3{}       //compile error: static modifier not allowed here
  }
}
and yet, it's legal to declare within it, the static class S1.
This contradicts the explanation given for this question, which says:
Only classes declared as members of top-level classes can be declared static.
As the positioning of S2 demonstrates, as long as only static classes are involved, it seems that nesting can continue to any depth.

Or, maybe I'm getting the terminology muddled up here?

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

Re: About Question com.enthuware.ets.scjp.v6.2.456 :

Post by admin »

The problem is that Sun (when it had control over Java) has changed its terminology a couple of times on this. Earlier, when the explanation was written, static nested class was considered a top level class. Later on they changed the terminology.
Also, in section 8.1.3, it also says, "An inner class is a nested class that is not explicitly or implicitly declared static." Thus, Inner1 is not a nested class.

Since there hasn't been any new development on the Java 6 version of the exam, it is not clear which terminology one should go with. It is your call.

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

TwistedLizard
Posts: 57
Joined: Sat Mar 01, 2014 1:48 pm
Contact:

Re: About Question com.enthuware.ets.scjp.v6.2.456 :

Post by TwistedLizard »

That explains it.
Thank you.

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 41 guests