• Post Reply Bookmark Topic Watch Topic
  • New Topic

private class  RSS feed

 
Arun kumar Maalik
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
private class Second{
public void showData(){
System.out.println("The Arun kumar maalik");
}
}

public class first{
Second b=new Second();
public static void main(String[] args){
Second p=new Second();
p.showData();
}
}
Hi everbody in the class Second why can we not declear it as private, also i would like to know one thing that in a class why there is no public class more than 1.

with regard

Arun kumar maalik
 
Jeroen T Wenting
Ranch Hand
Posts: 1847
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A private class would be accessible only to itself. That's of course rather useless, you could never instantiate it nor can you call static methods on it.
In other words for the rest of the world the class doesn't exist, therefore essentially it doesn't exist.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why there is no public class more than 1.


Is this asking why there can only be one public class in a ".java" soure file? I think that was just to simplify life for the compiler, JVM and other tools. Oh, and humans, too. When they need to find source code or a compiled class they look for a file with the same name.
[ July 09, 2006: Message edited by: Stan James ]
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to Java in General (Beginner).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!