1Z0-803 · Question #264
Given the code fragment: class Student { int rollnumber; String name; List cources = new ArrayList(); // insert code here public String toString() { return rollnumber + " : " + name + " : " + cources;
The correct answer is C. Student(int i, String name, List cs) {. Not A: Student has private access line:Student s = new Student(123,"Fred", cs); Not D: Cannot be applied to given types. Line:Student s = new Student(123,"Fred", cs);
Question
Given the code fragment:
class Student { int rollnumber; String name; List cources = new ArrayList(); // insert code here public String toString() { return rollnumber + " : " + name + " : " + cources; } } And, public class Test { public static void main(String[] args) { List cs = newArrayList(); cs.add("Java"); cs.add("C"); Student s = new Student(123,"Fred", cs); System.out.println(s); } } Which code fragment, when inserted at line // insert code here, enables class Test to print 123 :
Fred : [Java, C]?
Options
- Aprivate Student(int i, String name, List cs) {
- Bpublic voidStudent(int i, String name, List cs) {
- CStudent(int i, String name, List cs) {
- DStudent(int i, String name,ArrayList cs) {
How the community answered
(36 responses)- A3% (1)
- B14% (5)
- C78% (28)
- D6% (2)
Explanation
Not A: Student has private access line:Student s = new Student(123,"Fred", cs); Not D: Cannot be applied to given types. Line:Student s = new Student(123,"Fred", cs);
Topics
Community Discussion
No community discussion yet for this question.