Chapter 3       

First Program in Java

Syntax for deceleration of class
access specifier class ClassName
{
/* Body of class is followed by curly bracket*/
}
An outer class can be followed by either public access specifier or default access specifier.
Name of class and name of source code must be same.
The main() function must follow the following prototype :
public static void main (String [] args)
{
// Body of main() function
}
Code of HelloWorld.java
class HelloWorld
{
public static void main (String [] args)
{
System.out.println("Hello World");
}

}
Comments :-
a. Here System is a predefined class.
b. out is a static member reference variable of System class which contains address of an variable of PrintStream class.
c. println() is a member function of PrintStream class.
Output :-
Hello World
We have to write an access specifier with every member in a class.

Comments

Popular posts from this blog