• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

asking about public private n protected  RSS feed

 
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi there,
i hopr u r doing fine,had to ask something,given below:
case 1 :private class Ss{
case 2 :protected class Ss{
case 3 :public class Ss{
my question is
In case 1 error is genereted why
In case 2 erroe is genereted why
in case 3 there is no error why
please tell me that wat is the basic difference b/w them n why in two cases error is genereted n in last case there is no error.i hope that u ppl will help me asap.
take care
with regards
kumar abhay
[This message has been edited by Cindy Glass (edited November 26, 2001).]
 
kumar abhay
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
note:question was written wrong by mistake so it is the same question with nothing missing.
hi there,
i hopr u r doing fine,had to ask something,given below:
case 1 private class Ss{
case 2 protected class Ss{
case 3 public class Ss{
my question is
In case 1 error is genereted why
In case 2 erroe is genereted why
in case 3 there is no error why
please tell me that wat is the basic difference b/w them n why in two cases error is genereted n in last case there is no error.i hope that u ppl will help me asap.
take care
with regards
kumar abhay
 
Sheriff
Posts: 9087
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Java, a top level class may only be public or default (no access modifier). You may not declare a class private or protected unless it is an inner class.
 
kumar abhay
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi there,
could u make it more clear plz.
take care
with regards
kumar abhay
 
Marilyn de Queiroz
Sheriff
Posts: 9087
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<pre>
public class myClass{} // OK
class myClass{} // OK
protected class myClass{} // not allowed in Java
private class myClass{} // not allowed in Java

If you want to know why they are not allowed, you will have to ask James Gosling, the creator of the Java language.

class Outer
{
private class InnerOne{} // OK
protected class InnerTwo{} // OK
class InnerThree{} // OK
public class InnerFour{} // OK
}
Inner classes are different.
</pre>
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!