Programming Concepts using Java, End Term
Consider the Java code given below.
class Student{ private String name; public Student(String n){ this.name = n; } public Student(Student s){ this.name = s.name; } public void setName(String n){ name = n; } public String getName(){ return name; }}public class Test{ public static void main(String[] args){ Student s1 = new Student("Ram"); Student s2 = s1; Student s3 = new Student(s1); s1.setName("Rahul"); System.out.println("s2.name : " + s2.getName()); System.out.println("s3.name : " + s3.getName()); }}What will the output be?
Consider the Java code given below. class Student{ private String name; public Student(String n){ this.name = n; } public Student(Student s){ this.name = s.name; } public void setName(String n){ name = n; } public String getName(){ return name; } } public class Test{ public static void main(String[] args){ Student s1 = new Student("Ram"); Student s2 = s1; Student s3 = new Student(s1); s1.setName("Rahul"); System.out.println("s2.name : " + s2.getName()); System.out.println("s3.name : " + s3.getName()); } } What will the output be? Assume that the file “`data.txt`” contains the following two lines of text. india is my country india is my country 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("data.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 = {10, 8, 22, 13, 7}; Stream.of(a).map((i) -> i - 10) .filter((i) -> i% 2 == 0) .forEach((x) -> System.out.println(x)); } } What will the output be?