answersLogoWhite

0

Can you have multiple main method in the same class?

Updated: 8/20/2019
User Avatar

Wiki User

12y ago

Best Answer

according to my knowledge it is no a main can have multiple classes but a class cannot have multiple mains...main indicates the beginning of a program and if we have n number of mains then the compiler will show an error in all the main program that we write

User Avatar

Wiki User

12y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

12y ago

yes

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Can you have multiple main method in the same class?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Can you have a multiple main method in the same class?

no


How you compare and contrast overloading and overriding methods in java?

Method overloading is when you have multiple methods in a class that have the same name but a different signature. Method overriding is similar to method overloading, with a small difference. In overriding, a method in a parent class is overridden in the child class. The method in the child class will have the same signature as that of the parent class. Since the method in the child class has the same signature & name as the method of its parent class, it is termed as overriding. In situations where you may have to explicitly call the parent class method you can use the "super" keyword and for explicitly calling the current objects method you can use the "this" keyword.


What is the scope of method overloading and overriding?

Overloading happens when you have multiple methods in the current class that have the same name but different signature. The scope of method overloading is "Within the current class" Overriding happens when your current class extends another class (the parent class) and provides implementation for a method that is already available in the parent class. The scope of method overriding too is "Within the current class"


What is the purpose of method overriding?

Assuming class A has a method named getXXX() and class B is a sub class of class A. Now, if we write a method with the same name getXXX() in class B, with exactly the same signature as class A, it is called overriding a method. The method getXXX() in class A becomes the overridden method.


What is the main difference between inheritance and polymorphism?

The main difference is that: neither of them are related to one another. They have nothing similar between them and are totally different. The only point here is that they are both used in Java which can be stated as a similarity. Inheritance is the feature wherein functionality from one class is available for another class. Polymorphism refers to the feature wherein the same entity exists as multiple items. Ex: method overriding, method overloading etc.


Why java doesnot support multiple inheritence?

Multiple inheritance:The concept of Getting the properties from multiple class objects to sub class object with same priorities is known as multiple inheritance.Java Doesn't Support multiple Inheritance.Diamond problem:In multiple inheritance there is every chance of multiple properties of multiple objects with the same name available to the sub class object with same priorities leads for the ambiguity.We have two classes B and c which are inheriting A class properties.Here Class D inheriting B class and C class So properties present in those classes will be available in java.But both classes are in same level with same priority.If we want to use show() method that leads to ambiguityThis is called diamond problem.Because of multiple inheritance there is chance of the root object getting created more than once.Always the root object i.e object of object class hast to be created only once.Because of above mentioned reasons multiple inheritance would not be supported by java.Thus in java a class can not extend more than one class simultaneously. At most a class can extend only one class. source: instanceofjavaforus.blogspot.in/2014/12/why-java-does-not-supports-multiple.html


What should you make static in Java?

Static keyword signals something that is shared among all objects of the same class: i.e. a variable that all objects of the class can reference to, or method that all objects of the class can access. Usually, class constants are made static since it is the same in all objects of the same class thus it saves space not having to have variables for the same data for each class. But usually private instances should not be made static since it creates some strange situations, i.e. if you modify the data of one object, the data of the other object of the same class is also changed. Statics methods are common in main classes, in fact the main method itself is static, meaning it does not need a object to call it. The helper methods in a main class is usually static, since main classes are non-instantiable.


Why you use overloading and overriding?

Overloading the same method name with different number of arguments (and the data types), and perhaps with a different returned data type. The method signatures are different, only the names are the same. Overriding is to change the same method name with different implementation (the method body). The method signature stays the same.


Can a private method be overridden?

No. A method that is declared as private in a class is not inherited by any other class and hence if another class that extends this class declares a method with the same name and signature, it does not mean that this method is overridden. It is an entirely separate entity.


Why you give the constructor name same as class name?

Constructor is just like method in class.it actually used for intialising members of class, lets consider ex. class construct { constrct(){} } in main() you hav to provide.. construct c1=new construct(); new construct() means calling the method of class,and which is used to initailise members of same class implicitly. this it is necessary for constructor to have same name


Why does java not support multiple inheritence?

The superclass of all the classes in Java is Object,So any class we created is a instance of Object. Assume there is a class Father and Class Uncle,Now the class called child will have to inherit the features of father and Uncle which inturn will have some common features.So the child class would not be sure of whether to inherit the common feature from Father or uncle. This is known as the diamond problem - http://en.wikipedia.org/wiki/Diamond_problem There is nothing like virtual in Java


What is method overriding and overloading in java?

Overloading is the means by which we can provide two or more different definitions of the same method in the same namespace. Overriding is the means by which a derived class may redefine the meaning of a base class method.