Programming Concepts using Java, End Term
Consider the Java code given below.
class Monitor { public void screenSize() { System.out.println("Normal screen size"); } public void resolution() { System.out.println("Normal resolution"); }}class LCD extends Monitor { public void screenSize() { System.out.println("Screen size is large"); }}class LED extends Monitor { public void screenSize() { System.out.println("Screen size is medium"); } public void resolution() { System.out.println("HD resolution"); }}public class Test { static void show(Monitor[] monitors) { for (int i = 0; i < monitors.length; i++) { monitors[i].screenSize(); monitors[i].resolution(); } } public static void main(String[] args) { Monitor[] monitors = {new LCD(), new LED()}; // LINE 1 show(monitors); }}Choose the correct option.
Consider the Java code given below. class Monitor { public void screenSize() { System.out.println("Normal screen size"); } public void resolution() { System.out.println("Normal resolution"); } } class LCD extends Monitor { public void screenSize() { System.out.println("Screen size is large"); } } class LED extends Monitor { public void screenSize() { System.out.println("Screen size is medium"); } public void resolution() { System.out.println("HD resolution"); } } public class Test { static void show(Monitor[] monitors) { for (int i = 0; i < monitors.length; i++) { monitors[i].screenSize(); monitors[i].resolution(); } } public static void main(String[] args) { Monitor[] monitors = {new LCD(), new LED()}; // LINE 1 show(monitors); } } Choose the correct option. Consider the code given below that checks whether two candidates are from the same college. Method equals is overridden to compare two Candidate objects as follows. If two candidates are from the same college then they are said to be equal. Based on the given information, answer the question that follows. class Candidate { private String name; private String college; // Constructor to initialize instance variables public String toString() { return name; } public boolean equals(Object obj) { // CODE BLOCK } } public class Test { public static void main(String[] args) { Candidate c1 = new Candidate("Shreya", "IITMadras"); Candidate c2 = new Candidate("Hari", "IITDelhi"); Candidate c3 = new Candidate("Aisha", "IITMadras"); if (c1.equals(c3)) { System.out.println(c1 + " and " + c3 + " belong to the same college"); } if (c2.equals(c3)) { System.out.println(c2 + " and " + c3 + " belong to the same college"); } } } Choose the correct option to fill in place of CODE BLOCK so that the output is: Shreya and Hari belong to the same college Consider the Java code given below. class Intern { private String name; public Intern(String n) { name = n; } public Intern(Intern i) { this.name = i.name; } public void setName(String n) { name = n; } public String getName() { return name; } } public class Test { public static void main(String[] args) { Intern i1 = new Intern("Jaya"); Intern i2 = new Intern(i1); Intern i3 = i1; i1.setName("Subash"); System.out.println(i1.getName()); System.out.println(i2.getName()); System.out.println(i3.getName()); } } What will the output be?