• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

any suggestions on this "outer class"

 
anandkrisnan variar
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if there are 2 outer classes being defined in the same file as follows, what is the class modifier for "secondOuter" by default (e.g. private, protected)?
public class FirstOuter {...}
class SecondOuter {...}
Then, what is the class modifier "Inner" by default (private, protected)?
public class Outer {
class Inner {...}
}
 
Monisha Talwar
Ranch Hand
Posts: 102
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not sure I quite understood your question...
1. If you have more than 1 top level classes, only 1 can be public. The other can be private, protected or default access.
When you say what is the default....well, when you have no access modifier, its the package access or default access and thats the default
2. For inner classes, you can have any access modifier - Public, Private, protected or default. Again if you don't give it any access modifier - it is the default access.
Monisha.
 
Reshma Shanbhag
Ranch Hand
Posts: 204
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Monisha,
Most of what you have mentioned is right except for..

1. If you have more than 1 top level classes, only 1 can be public. The other can be private, protected or default access.

Top level classes can have either 'public' or no access modifier. If u declare a top level class with 'private' or protected modifier it gives a complie time error.
Reshma
[ April 08, 2003: Message edited by: Reshma Pai ]
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A top-leval class can have public, abstract, final and strictfp modifiers. These are valid:
public abstract strictfp class A {}
public final strictfp class B {}
 
Monisha Talwar
Ranch Hand
Posts: 102
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Woow! Thanks for correcting me Reshma...I don't believe myself ...Yep top level class can't be private or protected ! Thats the first thing you learn! Duh!
And I plan to take the exam soon...
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic