204k views
2 votes
Which of the following method declarations can be a constructor?

I. public static void Qwerty() { start = 0; max = 1000; }
II. public Qwerty() { start = 0; max = 1000; }
III. public Qwerty(int s, int m) { start = s; max = m; }
a. II & III only
b. II only
c. I only
d. I, II & III
e. III only

User Brian Yeh
by
8.0k points

1 Answer

2 votes

Final answer:

A constructor is a special method used to initialize objects in a class. Option II and option III can be constructors, while option I cannot. The correct answer is a. II & III only.

Step-by-step explanation:

A constructor is a special method that is used to initialize objects in a class. It has the same name as the class and does not have a return type. In the given options, only option II and option III can be constructors. Option II is a default constructor, which takes no arguments, and option III is a parameterized constructor, which takes two integer arguments. Option I cannot be a constructor because it is a static method and does not have the same name as the class. Therefore, the correct answer is a. II & III only.

User Hutingung
by
7.7k points