nerdexam
Oracle

1Z0-808 · Question #96

Given the code fragments: ``java 9. class Student { 10. int rollnumber; 11. String name; 12. List<String> courses = new ArrayList<>(); 13. // insert code fragment here 14. public String toString(){…

Sign in or unlock 1Z0-808 to reveal the answer and full explanation for question #96. The question stem and answer options stay visible for context.

Java Class Design

Question

Given the code fragments:
9. class Student {
10. int rollnumber;
11. String name;
12. List<String> courses = new ArrayList<>();
13. // insert code fragment here
14. public String toString(){
15. return rollnumber + ":" + name + ":" + courses;
16. }
17. }

And,

public class Test {
 public static void main (String[] args) {
 List<String> cs = new ArrayList<>();
 cs.add("Java");
 cs.add("C");
 Student s = new Student(123,"Fred",cs);
 System.out.println(s);
 }
}
Which code fragment, when inserted at line 13, enables class Test to print 123 : Fred : [Java, C] ?

Options

  • Aprivate Student(int i, String name, List cs) { /* initialization code goes here */ }
  • Bpublic void Student(int i, String name, List cs) { /* initialization code goes here */ }
  • CStudent(int i, String name, List cs) { /* initialization code goes here */ }
  • DStudent(int i, String name, ArrayList cs) { /* initialization code goes here */ }

Unlock 1Z0-808 to see the answer

You've previewed enough free 1Z0-808 questions. Unlock 1Z0-808 for full answers, explanations, the timed quiz mode, progress tracking, and the master PDF. Question stem and options stay visible so you can still see what's on the exam.

Topics

#constructors#access modifiers#constructor syntax#class instantiation
Full 1Z0-808 Practice