The code compiles fine. At runtime an IndexOutOfBoundsException is thrown when the third (as value of list size=2) list item is fetched. Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 2, Size: 2 at java.util.ArrayList.rangeCheck(Unknown Source) at java.util.ArrayList.get(Unknown Source)
Question : Which statement is/are true? I. Default constructor only contains "super();" call. II. We can't use any access modifier with a constructor. III. A constructor should not have a return type.
Statement I is correct as the default constructor only contains super() call Statement II is incorrect as we can use any access modifier with a constructor. Statement III is correct as constructor can't have return type, even void. So option D is correct.
Question : You have been given following code
public class Student { public String name = ""; public int age = 0; public String major = "Undeclared"; public boolean fulltime = true;
public void display() { System.out.println("Name: " + name + " Major: " + major); }
public boolean isFullTime() { return fulltime; } }
public class TestStudent { public static void main(String[] args) { Student bob = new Student(); bob.name = "Bob"; bob.age = 18; bob.year = 1982; } }