[JAVA rookie] ask the question about whether JAVA must have main method.

topic description

clipboard.png

sources of topics and their own ideas

item bank of training courses

my question:
shouldn"t this topic be choose B?
I can understand that the options of An and C are wrong. With regard to the D option, there must be a main method in the JAVA class. Isn"t that right?
B option, you must declare the class with class. Is that right? Is there any counterexample?

Apr.01,2021

you don't have to declare class, for example, enum interface, they are also classes, b is wrong, d is not necessary to have main method, and there is a problem with the wrong topic


of course not.
if your java program is executable, you do need the main method.
but what if it's a class library written for someone else?

class XXX {
//...
}

is there no main??


is wrong !


it is not necessary to have a main method.

such as:

class Bird{
    private String name;
    
    public void fly(){
        System.out.println("fly...")
    }
}
class Game{
    public static void main(){
        Bird bird = new Bird();
        bird.fly();
    }
}

there is no main method for Bird here


the examination is not rigorous, so you can choose the wrong item

.
Menu