answersLogoWhite

0

no you can have a class with no public methods and even with a a private constructor

public class Example {

//constructor

private Example(){

}

}

User Avatar

Wiki User

15y ago

What else can I help you with?

Continue Learning about Engineering

What does public mean in java?

The keyword public is an access specifier. A variable or a method that is declared public is publicly accessible to any member of the project. Any class or method can freely access other public methods and variables of another class.


The name of a Java program file must match the name of the class with the extension java?

not exactly..... only If your class is public then the java program name should be the public class name with extension Sample.java >> public class Sample { public static void main(String[] args) { ..... } } NonPublicClass.java class SomeOtherName { ......... }


Is it possible to have more than one public class in the same file?

No. There can be multiple java classes in the same .java file, but the name of the file must match the name of the public class in the file.


What does the java program error expected public class MathPow.java mean?

The error "expected public class MathPow.java" typically indicates that the Java compiler is expecting a public class declaration in the file named MathPow.java. In Java, the filename must match the public class name defined within the file. If the class is not declared as public or if the filename does not correspond to the class name, the compiler will throw this error. To fix it, ensure that the class is declared as public and that the filename matches the class name exactly.


Can we write static public void main in java?

the method of an class that can is triggered when starting a Java application e.g. by running the command: "java MyProgram" Answer Public is an Access Specifier,static is a keyword which illustrates that method shared along all the classes.void illustrates that this method will not have any return type.main is the method which string has an argument. Public specifier makes the method visible outside the Class and because of the static nature of the method, JVM can call this main method without instantiating the class 'MyProgram'.

Related Questions

What will happen if a Java Class has no Main Method?

Nothing will happen. There is no restriction that every Java class must have a main method. The only program is that, this class cannot be executed as a standalone java program.


What does public mean in java?

The keyword public is an access specifier. A variable or a method that is declared public is publicly accessible to any member of the project. Any class or method can freely access other public methods and variables of another class.


The name of a Java program file must match the name of the class with the extension java?

not exactly..... only If your class is public then the java program name should be the public class name with extension Sample.java >> public class Sample { public static void main(String[] args) { ..... } } NonPublicClass.java class SomeOtherName { ......... }


Why main method is declared as public and static in java?

"public" is quite obvious - it must be accessible from outside. I am not quite sure about static; but I believe that is because the class is run directly, rather than creating an object based on the class.


Can a class get compilled without main in java?

No, all classes MUST have a main method.


Is it possible to have more than one public class in the same file?

No. There can be multiple java classes in the same .java file, but the name of the file must match the name of the public class in the file.


What does the java program error expected public class MathPow.java mean?

The error "expected public class MathPow.java" typically indicates that the Java compiler is expecting a public class declaration in the file named MathPow.java. In Java, the filename must match the public class name defined within the file. If the class is not declared as public or if the filename does not correspond to the class name, the compiler will throw this error. To fix it, ensure that the class is declared as public and that the filename matches the class name exactly.


What are the sun coding standards for naming a class in java?

Some naming conventions/standards for Java classes are: a. A java file must be saved with the name of the public class in the file b. A Java file can have only one public class but can have any number of other classes c. The class names must be in Camel Case. Ex: AnExampleClassForWikiAnswers is how class names should be coded d. Even methods must be in camel case with one difference that the first alphabet must be in lower case. Ex: getSampleDataFrWiki()


Can we write static public void main in java?

the method of an class that can is triggered when starting a Java application e.g. by running the command: "java MyProgram" Answer Public is an Access Specifier,static is a keyword which illustrates that method shared along all the classes.void illustrates that this method will not have any return type.main is the method which string has an argument. Public specifier makes the method visible outside the Class and because of the static nature of the method, JVM can call this main method without instantiating the class 'MyProgram'.


Java program file must match the name of class with extension true or false?

The name of the .java file should exactly match with the name of the public class in the file. Ex: public class Test { ..... } this file should be saved as Test.java


Can a .java file contain more than one java classes?

Yes, it can. However, there can only be one public class per .java file, as public classes must have the same name as the source file.


What is the executable method in java?

In Java, the executable method is the main method, which serves as the entry point for any standalone Java application. It is defined as public static void main(String[] args), where String[] args allows for command-line arguments to be passed to the program. The main method must be declared as public and static, and it returns no value (void). When a Java program is run, the Java Virtual Machine (JVM) looks for this method to start the execution of the program.