Which three statements are true about the structure of a Java class? (Choose three.)
Which three statements are true about the structure of a Java class? (Choose three.)
A class can have final static methods, which means the method belongs to the class itself and cannot be overridden in subclasses. A class can have overloaded private constructors to control object creation within the class while still allowing different ways to initialize objects. Methods and fields are optional components of a class; a class can exist without explicitly defined methods or fields, but it must have at least one constructor. Fields do not always need to be explicitly initialized before use because they have default values.
sorry, I was wrong. The correct is CDF
C. A class can have final static methods. Yes, a class can have final static methods. The final modifier means that the method cannot be overridden in subclasses, and the static modifier means that the method belongs to the class itself, not to instances of the class. D. A class can have overloaded private constructors. Yes, a class can have overloaded private constructors. Overloading means having multiple constructors with different parameter lists. Private constructors restrict instantiation outside the class but allow overloading. E. Fields need to be initialized before use. Yes, fields in Java need to be initialized before they are used. If they are not explicitly initialized, they will be assigned default values (for example, 0 for numeric types, null for reference types).
The incorrect statements are: A. A class cannot have the same name as its field. This statement is incorrect. A class can have a field with the same name as the class itself, although it's not recommended for clarity. B. A public class must have a main method. This statement is incorrect. While a class with a public static void main(String[] args) method is required to be the entry point for a Java application, not all public classes need to have a main method. F. Methods and fields are optional components of a class. This statement is incorrect. In Java, a class must have at least one constructor (which can be the default constructor) and can contain methods and fields, but a class must have a constructor to initialize its instances.
classs1{}//ok class ss{ int ss = 0;//ok private ss(){}//pl private ss(String s){}//ok final static void m1(){}//ok } so cdf
Answer is CDF
Answer is CDF, Option E - Static fields and wrappers fields have default value. Do not need to be initialized.
CDF is the answer. Classes can have final static methods (tested)
A, B, D, F are like what iSnover said. C is correct as static and final are not the oppositve. abstract and final are opposite. Final just means the method / class cannot be inherited further, and static method means the method is available to use without initializing any objects of the class. E is wrong as fields can be uninitialized. They remain at their default values. (char --> \u0000, boolean --> false, short / int / long / float / double --> numerical 0 in their own types, String / Object --> null)
The correct answer is DEF: A -> Wrong, a class can have the same name as its field. B -> Wrong, a public class doesn't need to have a main method, you can create empty public class. C -> Wrong, you can't have static and final methods, you can only put one of the 2 because final doesn't allow changes D -> Correct, a class can overload private constructors, just extend the other class and use the same view (private) or greater. E -> Correct, Fields need to be initialized before use, as Java is a typed language. F -> Correct, as I said before, you can create an empty class.
C is wrong? literally open any online java compiler, add 'final' to the main method, see if it will work or not (it works btw)