1Z0-808 practice question 2 of 30

Which three statements are true about the structure of a Java class? (Choose three.)

Full set: 224 questions
Answer options
A: A public class must have a main method.
B: A class can have only one private constructors.
C: A method can have the same name as a field.
D: A class can have overloaded static methods.
E: The methods are mandatory components of a class.
F: The fields need not be initialized before use.
Correct Answer:
Explanation

--- QUESTION #97 --- Which three statements are true about the structure of a Java class? (Choose three.)

Correct Answer: C, D, F
Explanation:
(C) A method can have the same name as a field because they exist in different namespaces within the class.
(D) Static methods can be overloaded, just like instance methods, by defining multiple static methods with the same name but different parameter lists.
(F) Class fields (static variables) and instance fields are automatically initialized with default values (e.g., 0 for numeric types, null for object references) if not explicitly initialized. Local variables, by contrast, must be initialized. Why Incorrect Options are Wrong: A: A class, even a public one, is not required to have a main method. Only the application entry-point class needs one. B: A class can have multiple overloaded private constructors, provided their parameter lists differ. E: Methods are not mandatory. A class can be legally defined with only fields, or even be completely empty.
References: Oracle, The Java™ Tutorials. "Initializing Fields." "If a primitive type... is not initialized, it has a default value." Gosling, J., Joy, B., Steele, G., & Bracha, G. (2014). The Java™ Language Specification, Java SE 8 Edition. Section 8.4.9, "Overloading". This section applies to all methods, including static ones. Gosling, J., Joy, B., Steele, G., & Bracha, G. (2014). The Java™ Language Specification, Java SE 8 Edition. Section 6.3, "Scope of a Declaration". This section details the different namespaces for types, fields, and methods.

Scroll to Top