Can a .java file contain ONLY one class file ?

All public classes need to be declared in .java files of their own. Try the following code and give your understanding.

[java title=”HelloWorld.java” gutter=”true” highlight=”5″]
public class HelloWorld {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("Hello World !!");
HelloWorldBrother hwc = new HelloWorldBrother ();

}

}

class HelloWorldBrother
{
public HelloWorldBrother ()
{
System.out.println ( "Hello World’s Brother Class is called" );
}
}
[/java]

Now in the class HelloWorldBrother (the brother of the HelloWorld class 🙂 ), there is no access modifier specified ? What does this mean ?

What is the default access modifier to a Java Class ?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s