Programming Concepts using Java, End Term
Method Stream.iterate(e, f) returns an infinite sequential ordered Stream produced by iterative application of a function f to an initial element e, producing a Stream consisting of e, f(e), f(f(e)), etc. Based on the above information, consider the code given below, and answer the question that follows.
import java.util.stream.*;public class Test { public static void main(String[] args) { Stream.iterate(0, n -> n+3).limit(6).filter(n -> n % 2 == 0) .forEach(num -> System.out.print(num+" ")); }}What will the output be?
Method Stream.iterate(e, f) returns an infinite sequential ordered Stream produced by iterative application of a function f to an initial element e, producing a Stream consisting of e, f(e), f(f(e)), etc. Based on the above information, consider the code given below, and answer the question that follows. import java.util.stream.*; public class Test { public static void main(String[] args) { Stream.iterate(0, n -> n+3).limit(6).filter(n -> n % 2 == 0) .forEach(num -> System.out.print(num+" ")); } } What will the output be? Consider the following java code class Worker implements Cloneable{ String name; public Worker(String n) { name = n; } public Worker clone() throws CloneNotSupportedException{ return (Worker)super.clone(); } } class Work implements Cloneable{ String job; Worker[] wk; public Work(String j, Worker[] w) { job = j; wk = w; } public Work clone() throws CloneNotSupportedException{ Work t = (Work)super.clone(); t.wk = t.wk.clone(); return t; } } public class Test { public static void main(String[] args) throws CloneNotSupportedException{ Worker[] w1 = {new Worker("ABC"), new Worker("XYZ")}; Work obj1 = new Work("Painting", w1); Work obj2 = obj1.clone(); Worker[] w2 = obj2.wk; w2[0].name = "MNO"; obj2.job = "Printing"; System.out.println(obj1.job +" : " + obj1.wk[0].name); System.out.println(obj2.job +" : " + obj2.wk[0].name); } } What will the output be? Consider the java code given below class Employee{ private String name; private double salary; public Employee() { this.salary = 40000.0; } public Employee(Employee e) { this.name = e.name; this.salary = e.salary; } public void setName(String name) { this.name = name; } public String getName() { return name; } public void setSalary(double salary) { this.salary = salary; } public double getSalary() { return salary; } } public class Test{ public static void main(String[] args) { Employee obj1 = new Employee(); Employee obj2 = obj1; Employee obj3 = new Employee(obj1); obj1.setSalary(50000.0); obj1.setName("Anand"); obj2.setName("Karthik"); obj3.setName("Shannu"); System.out.println(obj1.getName() +": " + obj1.getSalary()); System.out.println(obj2.getName() +": " + obj2.getSalary()); System.out.println(obj3.getName() +": " + obj3.getSalary()); } } What will the output be?