Programming Concepts using Java, End Term
Consider the Java program below.
Consider the Java code given below.
class Student { String name; public Student(String n) { name = n; } public String toString() { return "Name = " + name; }}class Leader extends Student { private int marks; public Leader(String n, int m) { super(n); marks = m; } public Leader(Leader l) { super(l.name); marks = l.marks; } public String toString() { return super.toString() + ", " + "Marks = " + marks; }}public class College { public static void main(String args[]) { Student l1 = new Leader("Rohan", 97); Student l2 = new Leader((Leader) l1); l2.name = "Ananya"; System.out.println(l1 + "\n" + l2); }}What will the output be?
Consider the Java program below. Consider the Java code given below. class Student { String name; public Student(String n) { name = n; } public String toString() { return "Name = " + name; } } class Leader extends Student { private int marks; public Leader(String n, int m) { super(n); marks = m; } public Leader(Leader l) { super(l.name); marks = l.marks; } public String toString() { return super.toString() + ", " + "Marks = " + marks; } } public class College { public static void main(String args[]) { Student l1 = new Leader("Rohan", 97); Student l2 = new Leader((Leader) l1); l2.name = "Ananya"; System.out.println(l1 + "\n" + l2); } } What will the output be? Method `Optional.ofNullable(T value)` returns an `Optional` that describes the specific value, if non-null; otherwise returns an empty `Optional`.\ Based on this description, consider the code given below, and answer the question that follows. import java.util.*; class GoldQC { String type; int karats; public GoldQC(int k){ karats = k; } public GoldQC(String t, int k){ type = t; karats = k; } } public class Test { public static void main(String[] args) { var goldList = new ArrayList<GoldQC>(); goldList.add(new GoldQC("Ring", 24)); goldList.add(new GoldQC(18)); for (GoldQC g: goldList) { System.out.print("karats = " + g.karats + ", type = "); Optional<String> karatsValue = Optional.ofNullable(g.type); karatsValue.ifPresentOrElse(t -> System.out.println(t), () -> System.out.println("unknown") ); } } } Choose the correct option. Consider the Java code give below. abstract class Operation implements Runnable { static int result = 0; } class AddOperation extends Operation { public void run() { if (result != 8) { result = result + 3; } } } class MultiplyOperation extends Operation { public void run() { if (result != 9) { result = result * 2; } } } public class MathOperations { public static void main(String[] args) { Operation addOp = new AddOperation(); Operation multiplyOp = new MultiplyOperation(); Thread t1 = new Thread(addOp); Thread t2 = new Thread(multiplyOp); t1.start(); t2.start(); System.out.println(Operation.result); } } Choose the correct option.