Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

asking about public private n protected

 
kumar abhay
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
 
Marilyn de Queiroz
Sheriff
Posts: 9066
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: 9066
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>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic