Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

Is it possible to define a method in java class but provide it’s implementation in the code of another language like c?

998


How is abstraction implemented in java ?

929


What is java util concurrentmodificationexception?

880


What is the difference between synchronized and synchronized block?

1018


What do you understand by abstract classes?

1028


What access modifiers can be used for class ?

983


What is meant by the value of a variable?

875


Explain the use of sublass in a java program?

988


How transient variable is different from volatile variable?

1036


Can we call the constructor of a class more than once for an object?

1054


What does exp mean in math?

948


What is the Scope of Static Variable?

1180


What is the full meaning of java?

1006


What are different access specifiers in java? Explain

1076


What are multiple inheritances?

1071