JAVA COADING STANDARD PART . 6
Java Coading Standard
Question :- In single java file we can create multiple classes and we can declare multiple main method inside java file?
Answer :- Yes we can define more than one main method in single java file.
Simple hello world program in java
Import java.lang.*;
Class Test
{
public static void main(string[]ar)
{
System.out.println(“ hello world “);
}
}
Java Single File We Can Create a Multiple Class
* We can declared only one class should be public No two class should be declared as public in single java file.
* And make sure file Name should be same as public class name. if you using any public class.
* It is recommended to create only class in single java file.
Ex. :-
Import java.lang.*;
Class A
{
public static void main(string[]ar)
{
System.out.println(“ Welcome to weindians.in 1″);
}
}
// CREATE ANOTHER NEW CLASS
Class B
{
public static void main(string[]ar)
{
System.out.println(“ Welcome to weindians.in 2″);
}
}
// CREATE ANOTHER NEW CLASS
Class C
{
public static void main(string[]ar)
{
System.out.println(“ Welcome to weindians.in 3″);
}
}
To run the program gives output :-
Welcome to weindians.in 1
Welcome to weindians.in 2
Welcome to weindians.in 3
Now Friends If you like this post please tell us how can we help you to provide better knowledge?
If this post is use full for you please share the post with your friends.
Please follow as facebook : www.facebook.com
Please follow as twitter : www.twitter.com
And more information please visit here : www.weindians.in
Please Subscribe on youtube : www.youtube.com