import java.util.Scanner; class FirstClass { private String firstName; private String secondName; public FirstClass(String firstName, String secondName) { this.firstName = firstName; this.secondName = secondName; } public String getFirstName() { return firstName; } public void setFirstName() { Scanner in = new Scanner(System.in); firstName = in.nextLine(); } public String getSecondName() { return secondName; } public void setSecondName() { Scanner in = new Scanner(System.in); secondName = in.nextLine(); } }; public class MyClass { public static void main(String[] args) { FirstClass obj = new FirstClass("Dragu", "Stelian"); System.out.println("Name is: " +obj.getFirstName() + " " +obj.getSecondName()); System.out.print("Enter First Name: "); obj.setFirstName(); System.out.print("Enter Second Name: "); obj.setSecondName(); System.out.println("Name is: " +obj.getFirstName() + " " +obj.getSecondName()); } }
package myclass; import java.util.Scanner; class FirstClass { private String firstName; private String secondName; public FirstClass(String firstName, String secondName) { this.firstName = firstName; this.secondName = secondName; } public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getSecondName() { return secondName; } public void setSecondName(String secondName) { this.secondName = secondName; } }; public class MyClass { public static void main(String[] args) { FirstClass obj = new FirstClass("Dragu", "Stelian"); Scanner input = new Scanner(System.in); System.out.print("Enter First Name: "); obj.setFirstName = input.nextLine(); System.out.print("Enter Second Name: "); obj.secondName = input.nextLine(); System.out.println("Name is: " +obj.firstName + " " +obj.secondName); } }