Powered by Blogger.
Showing posts with label Syntax of java program. Show all posts
Showing posts with label Syntax of java program. Show all posts

Another Java Program for beginners | Java Programming

The name of the source file must be the same as the name of the public class declaration in that file. A source file can include more then one class declaration, but only one class can be declared public.

public class Welcome{
public static void main(String[]args){
Hello hello = new Hello();
  hello.display();
}
 }

 class Hello{
  public void display(){
System.out.println(”Welcome to Java world”);
  }
 }



Line 3 creates an object of Hello class named hello

Line 4 call the display() method of Hello class using the hello object
with the dot notation.

Line 8 declares a user-defined class Hello with default access control.

Line 9 declares a user-defined method named display().