Programming Concepts using Java, End Term
Consider the Java code given below.
class Customer{ private String name; public Customer(String n){ this.name = n; } public Customer(Customer c){ this.name = c.name; } public void setName(String n){ name = n; } public String getName(){ return name; }}public class Test{ public static void main(String[] args){ Customer c1 = new Customer("Latha"); Customer c2 = c1; Customer c3 = new Customer(c1); c1.setName("Geeta"); System.out.println("c2.name : " + c2.getName()); System.out.println("c3.name : " + c3.getName()); }}What will the output be?
Consider the Java code given below. class Customer{ private String name; public Customer(String n){ this.name = n; } public Customer(Customer c){ this.name = c.name; } public void setName(String n){ name = n; } public String getName(){ return name; } } public class Test{ public static void main(String[] args){ Customer c1 = new Customer("Latha"); Customer c2 = c1; Customer c3 = new Customer(c1); c1.setName("Geeta"); System.out.println("c2.name : " + c2.getName()); System.out.println("c3.name : " + c3.getName()); } } What will the output be? Assume that the file “`test.txt`” contains the following two lines of text. M.S Dhoni is a professional Indian cricketer M.S Dhoni is from jharkhand Consider the code given below. import java.io.*; import java.util.*; public class FileTest { public static void main(String[] args) { try { var in=new FileInputStream("test.txt"); var sc=new Scanner(in); var data=new TreeSet<String>(); while(sc.hasNext()) { data.add(sc.next()+" "); } for(String str:data) System.out.print(str); } catch (FileNotFoundException e) { System.out.println("File does not exist."); } catch (IOException e) { System.out.println("Error in writing a file."); } } } What will the output be? Consider the following java code import java.util.stream.*; public class Main{ public static void main(String[] args){ Integer[] a = {11, 8, 20, 13, 6}; Stream.of(a) .map((i) -> i - 8).filter((i) -> i% 2 == 0) .forEach((x) -> System.out.println(x)); } } What will the output be?