Why only one Class is public in one file? Explain in
details. Thanks in Advance.
Answer Posted / ganesh slv
/****** Program Starts Here ************/
/**
* Save this file as Class1.java. All should be in single
* file
*
* Date : 14.04.10
* @author Ganesh Slv
*/
public class Class1 { // Note this line
/* This Class is public. So your file name should be the
same name.
*/
public static void main (String arg[]) {
System.out.println (" This is from Class1.. ");
} // Main
} // Class1
class Class2 { // Note this line
/* This class is not public. so it doesn't matter
your file name.
*/
public static void main (String arg[]) {
System.out.println (" This from Class2..");
}
}
class Class3 {
/* This class Calls the main() in Class1.
*/
static public void main (String arg[]) {
System.out.println (" This is from Class3..");
// Creating obj to Class1
Class1 c1 = new Class1 ();
c1.main (arg); //Main must have one arg as String[] type
}
}
/********** Program Ends here ******/
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers
Which variable is the independent variable?
Why do we need strings in java?
What is :: operator in java 8?
What is the function of character?
Is java 11 paid version?
Explain different ways of creating a thread?
What is the default value of float and double datatype in java?
How many bits is a string?
Can a class extend 2 classes in java?
What is the difference between final, finally and finalize()?
What is javac in java?
What are the different access modifiers available in java?
What are the 6 functions?
What is singleton math?
What is the difference between Error, defect,fault, failure and mistake?