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(8, n -> n-1) .map(n -> n + 2) .filter(n -> n % 3 == 0) .limit(4) .forEach((x) -> System.out.print(x + " ")); }}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(8, n -> n-1) .map(n -> n + 2) .filter(n -> n % 3 == 0) .limit(4) .forEach((x) -> System.out.print(x + " ")); } } What will the output be? Consider the following java code class Player implements Cloneable{ String name; public Player(String n) { name = n; } public Player clone() throws CloneNotSupportedException{ return (Player)super.clone(); } } class Team implements Cloneable{ String teamname; Player[] ply; public Team(String tn, Player[] p) { teamname = tn; ply = p; } public Team clone() throws CloneNotSupportedException{ Team t = (Team)super.clone(); t.ply = t.ply.clone(); return t; } } public class Test { public static void main(String[] args) throws CloneNotSupportedException{ Player[] p1 = {new Player("Nikita"), new Player("Ram")}; Team t1 = new Team("Orange", p1); Team t2 = t1.clone(); Player[] p2 = t2.ply; p2[0].name = "Srikanth"; t2.teamname = "Mango"; System.out.println(t1.teamname +" : " + t1.ply[0].name); System.out.println(t2.teamname +" : " + t2.ply[0].name); } } What will the output be? Consider the java code given below class Instructor{ private String name; private double salary; public Instructor() { this.salary = 40.0; } public Instructor(Instructor t) { this.name = t.name; this.salary = t.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) { Instructor obj1 = new Instructor(); Instructor obj2 = obj1; Instructor obj3 = new Instructor(obj1); obj1.setSalary(50.0); obj1.setName("Suresh"); obj2.setName("Ram"); obj3.setName("Ravi"); 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?