Wiki User
∙ 11y agoThat would require a detailed explanation of each of the keywords involved; if you are just starting to learn Java, suffice it to say that the Java Virtual Machine looks for a method that has that precise signature. As to what happens if you do otherwise, try it out! Probably you will get different error messages, depending on what keywords you omit or change.
Wiki User
∙ 11y agoIf you declare the main method anything other than public, it will not run. If you declare main method as private, you would not be able to execute the class as a standalone java program. Any java class that needs to be executed as a standalone file needs to have a main method that is public, static and returns a void. Otherwise the Java compiler would not recognize the file as an executable standalone java file and would not allow you to run it.
no you can have a class with no public methods and even with a a private constructor public class Example { //constructor private Example(){ } }
It means that the method is visible from only within the current method. Also, any class that wants to use or invoke the private method has to create an object of the class in which the method is created in order to access/invoke it. The private access modifier is the most restrictive of the four java access modifiers. The total opposite of private is public which gives access to everyone.
If you omit either the "public" or the "private" keywoard, the access (to a field or method) will be the so-called "default access". The field or method will be visible for other classes, if they are in the same package.
Yes. During inheritance only the public members of the parent class are visible to the child class. If you declare a method or a variable as private, the child class cannot access it. In other words, the methods and variables are hidden from the derived class.
is a method to provide financial support for 'public-private partnerships' (PPPs) between the public and private sectors.
If you declare the main method anything other than public, it will not run. If you declare main method as private, you would not be able to execute the class as a standalone java program. Any java class that needs to be executed as a standalone file needs to have a main method that is public, static and returns a void. Otherwise the Java compiler would not recognize the file as an executable standalone java file and would not allow you to run it.
no you can have a class with no public methods and even with a a private constructor public class Example { //constructor private Example(){ } }
Public members in C++ have accessibility to any function that has scope to the instance of the class, whereas private members have accessibility only to functions of that class.
public means this can be accessed from any class private means this can be accessed only from the current class
It means that the method is visible from only within the current method. Also, any class that wants to use or invoke the private method has to create an object of the class in which the method is created in order to access/invoke it. The private access modifier is the most restrictive of the four java access modifiers. The total opposite of private is public which gives access to everyone.
Yes. It happens all the time. Think of a wedding reception, and a catering hall or a private restaurant.
class Rectangle{ private: int length; int width; public: void input(); void output(); };
Yes. It happens all the time. Think of a wedding reception, and a catering hall or a private restaurant.
Sure you can. The run method is just another java method that you can modify to be private or protected or have return types as Strings etc. But, this run method will not be invoked when you start the thread. Only the default public void run() will be invoked when you do a thread.start()
Yes you can. Try this: public class TestMain { /** * @param args */ public static final void main(String[] args) { System.out.println("Inside final mail method..."); } } It will print "Inside final mail method..." in the console.
by declaring in the header of the class: public/private interface [interfaceName] and do not write any method body(i.e. public void dance();)