174k views
4 votes
Which of the following is TRUE?

(a) In java, an instance field declared public generates a compilation error.
(b) int is the name of a class available in the package
(c) Instance variable names may only contain letters and digits.
(d) A class has always a constructor (possibly automatically supplied by the java compiler).
(e) The more comments in a program, the faster the program runs.

User Luizfzs
by
8.0k points

1 Answer

4 votes

Final answer:

Among the given options, the correct one is (d) A class has always a constructor (possibly automatically supplied by the Java compiler). The Java compiler provides a default constructor if one is not explicitly defined.

Step-by-step explanation:

The question relates to Java programming concepts, and among the given options, the true statement is (d) A class has always a constructor (possibly automatically supplied by the Java compiler). If a class does not have a constructor defined explicitly by the programmer, the compiler will automatically provide a default constructor that initializes the object. Option (a) is not true because in Java, fields can be declared as public without generating a compilation error. However, it's generally considered bad practice to do so as it violates encapsulation principles. Option (b) is incorrect; 'int' is a primitive type in Java, not a class name. Option (c) is false because in addition to letters and digits, instance variable names can include the underscore (_) and dollar sign ($) characters, although these are not commonly used. Lastly, option (e) is incorrect; the number of comments does not affect the runtime performance of a program as they are ignored by the compiler.

User Hristo Staykov
by
7.8k points