[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

.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b38d0b-2c137.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b38d0b-2c137.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?