Which code fragment, when inserted at line // insert code here, enables class Test to print 123 : Fred : [Java, C]?

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]?
A. private Student(int i, String name, List cs) {
/* initialization code goes here */
}
B. public void Student(int i, String name, List cs) {
/* initialization code goes here */
}
C. Student(int i, String name, List cs) {
/* initialization code goes here */
}
D. Student(int i, String name, ArrayList cs) {
/* initialization code goes here */
}

Download Printable PDF. VALID exam to help you PASS.

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.