Task - Object Cloning - Employee Details #15
Replies: 33 comments 1 reply
-
|
`class Address{ } } } public class UPIDriver { }` |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
|
`class Address { } class Location { } public class UPIPaymentApps implements Cloneable { } class Driver { |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
|
`import java.util.ArrayDeque; public class UPIPaymentsApp implements Cloneable { } class Location { } class Address { } class UPIDriver { }` |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
|
class Address { } class Location { } class UPIPaymentApps implements Cloneable { } class CloneDriver { |
Beta Was this translation helpful? Give feedback.
-
|
`class UPIPaymentApps implements Cloneable { } class Location{ } class Address{ } public class Payment{ } |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
|
`class Location{ } } } public class OnlineBanking { } |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
|
`class Address { } class Location { } class UPIApps implements Cloneable { } public class CloneExample { }` |
Beta Was this translation helpful? Give feedback.
-
|
class Location { } class Address { } public class UPIPaymentsApps implements Cloneable { } class UPIDriver { } |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
|
TASK 2: } class Address{ } class UPIPaymentApps implements Cloneable { } public class UPIDriver { } |
Beta Was this translation helpful? Give feedback.
-
|
`class Address { } class Location { } class UPIPaymentApps implements Cloneable { } class UPIDriver { } |
Beta Was this translation helpful? Give feedback.
-
`public class ObjectCloning { } class Address { } class Location { } class UPIPayments implements Cloneable { }` Sir I am getting NosuchMethodFoundError I am not getting why |
Beta Was this translation helpful? Give feedback.
-
|
`class Address { } class Location { } class UPIPaymentApps implements Cloneable { } public class DeepCopy { } |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
package collection.Bankx;
class Address {
Location location;
String state;
String country = "India";
public Address(Location location, String state) {
this.location = location;
this.state = state;
}
@Override
public String toString() {
return "\nCountry = " + country + "\nState = " + state + "\nLocation:" + location + "\n";
}
}
class Location {
String street;
String city;
public Location(String street, String city) {
this.street = street;
this.city = city;
}
@Override
public String toString() {
return "\nCity = " + city + "\nStreet = " + street;
}
}
class UPIApp implements Cloneable {
String name;
int dailyLimit;
double maxDailyAmount;
Address headOfficeLocation;
public UPIApp(String name, int dailyLimit, double maxDailyAmount, Address headOfficeLocation) {
this.name = name;
this.dailyLimit = dailyLimit;
this.maxDailyAmount = maxDailyAmount;
this.headOfficeLocation = headOfficeLocation;
}
@Override
protected Object clone() throws CloneNotSupportedException {
Location loc = new Location(this.headOfficeLocation.location.street, this.headOfficeLocation.location.city);
Address newDepObj = new Address(loc, this.headOfficeLocation.state);
return new UPIApp(this.name, this.dailyLimit, this.maxDailyAmount, newDepObj);
}
@Override
public String toString() {
return "\n---- Name = " + name + " ----\nDaily Limit = " + dailyLimit + "\nMax Daily Amount = "
+ maxDailyAmount + "\n-- Head Office Location: --"
+ headOfficeLocation + "\n";
}
}
public class Clonning {
public static void main(String[] args) throws Exception {
Location BHIMloc = new Location("123 park road", "Banglore");
Address BHIMadrs = new Address(BHIMloc, "Karnataka");
UPIApp bhim = new UPIApp("BHIM", 10, 100000, BHIMadrs);
// Before cloning
System.out.println("----------- Before Deep cloning: -----------");
System.out.println("BHIM app info:\n" + bhim);
// Deep copy
UPIApp payTm = (UPIApp) bhim.clone();
// Changing Data
payTm.name = "PayTm";
payTm.headOfficeLocation.location.city = "Mumbai";
payTm.headOfficeLocation.location.street = "456 RPTS Road";
payTm.headOfficeLocation.state = "Maharashtra";
System.out.println("----------- After Cloning -----------\nChanges in paytm\n" + payTm);
// Printing BHIM app info
System.out.println("BHIM app info after Cloning:\n" + bhim);
}
} |
Beta Was this translation helpful? Give feedback.
-
class Location {
String street;
String city;
public Location(String street, String city) {
this.street = street;
this.city = city;
}
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
@Override
public String toString() {
return "[ Street = " + street + " City = " + city + "]";
}
}
class Address implements Cloneable {
Location location;
String state;
String country;
public Address(Location location, String state, String country) {
this.location = location;
this.state = state;
this.country = country;
}
public Location getLocation() {
return location;
}
public void setLocation(Location location) {
this.location = location;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
@Override
protected Object clone() throws CloneNotSupportedException {
// TODO Auto-generated method stub
return super.clone();
}
@Override
public String toString() {
return "[State : " + state + " County : " + country + "]";
}
}
public class UPIPaymentApps implements Cloneable {
String appName = "BHIM";
int dailyLimit = 10;
double maxDailyAmount = 100000;
Address headOfficeLocation;
public UPIPaymentApps() {
}
public UPIPaymentApps(String appName, int dailyLimit, double maxDailyAmount, Address headOfficeLocation) {
this.appName = appName;
this.dailyLimit = dailyLimit;
this.maxDailyAmount = maxDailyAmount;
this.headOfficeLocation = headOfficeLocation;
}
@Override
public String toString() {
return "UPIPaymentApps [ " + "appName = " + appName + "\tMaxDailyAmount = "
+ maxDailyAmount
+ "\tDateLimit = " + dailyLimit + " ]";
}
@Override
protected Object clone() throws CloneNotSupportedException {
Location clone1 = new Location(headOfficeLocation.location.street, headOfficeLocation.location.city);
Address newObj = new Address(clone1, headOfficeLocation.state, headOfficeLocation.country);
return new UPIPaymentApps(this.appName, this.dailyLimit, this.maxDailyAmount, newObj);
}
}
class Driver {
public static void main(String[] args) throws CloneNotSupportedException {
Location location = new Location("NR PET", "Kurnool");
Address address = new Address(location, "Andhra Pradesh", "India");
UPIPaymentApps bhim = new UPIPaymentApps("BHIM", 10, 100000, address);
UPIPaymentApps paytm = (UPIPaymentApps) bhim.clone();
paytm.appName = "Paytm";
paytm.headOfficeLocation.location.city = "Noida";
paytm.headOfficeLocation.location.street = "Sector 5";
paytm.headOfficeLocation.state = "Uttar Pradesh";
System.out.println("BHIM Object ::");
System.out.println(bhim.headOfficeLocation + "\n" + bhim.headOfficeLocation.location);
System.out.println("\n\nPaytm Object ::");
System.out.println(paytm.headOfficeLocation + "\n" + paytm.headOfficeLocation.location);
}
} |
Beta Was this translation helpful? Give feedback.
-
class Location {
String street;
String city;
public Location(String street, String city) {
this.street = street;
this.city = city;
}
public String getStreet() {
return street;
}
public void setStreet(String street) {
this.street = street;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
@Override
public String toString() {
return "[ Street = " + street + " City = " + city + "]";
}
}
class Address implements Cloneable {
Location location;
String state;
String country;
public Address(Location location, String state, String country) {
this.location = location;
this.state = state;
this.country = country;
}
public Location getLocation() {
return location;
}
public void setLocation(Location location) {
this.location = location;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
@Override
public Object clone() throws CloneNotSupportedException {
// TODO Auto-generated method stub
return super.clone();
}
@Override
public String toString() {
return "[State : " + state + " County : " + country + "]";
}
}
public class UPIPaymentApps implements Cloneable {
String appName = "BHIM";
int dailyLimit = 10;
double maxDailyAmount = 100000;
Address headOfficeLocation;
public UPIPaymentApps() {
}
public UPIPaymentApps(String appName, int dailyLimit, double maxDailyAmount, Address headOfficeLocation) {
this.appName = appName;
this.dailyLimit = dailyLimit;
this.maxDailyAmount = maxDailyAmount;
this.headOfficeLocation = headOfficeLocation;
}
@Override
public String toString() {
return "UPIPaymentApps [ " + "appName = " + appName + "\tMaxDailyAmount = "
+ maxDailyAmount
+ "\tDateLimit = " + dailyLimit + " ]";
}
@Override
public Object clone() throws CloneNotSupportedException {
Location clone1 = new Location(headOfficeLocation.location.street, headOfficeLocation.location.city);
Address newObj = new Address(clone1, headOfficeLocation.state, headOfficeLocation.country);
return new UPIPaymentApps(this.appName, this.dailyLimit, this.maxDailyAmount, newObj);
}
}
class Driver {
public static void main(String[] args) throws CloneNotSupportedException {
Location location = new Location("Karol Bagh", "Delhi");
Address address = new Address(location, "Uttar Pradesh", "India");
UPIPaymentApps bhim = new UPIPaymentApps("BHIM", 10, 100000, address);
UPIPaymentApps paytm = (UPIPaymentApps) bhim.clone();
paytm.appName = "Paytm";
paytm.headOfficeLocation.location.city = "Ghaziabad";
paytm.headOfficeLocation.location.street = "Indrapuram";
paytm.headOfficeLocation.state = "Uttar Pradesh";
System.out.println("BHIM Object ::");
System.out.println(bhim.headOfficeLocation + "\n" + bhim.headOfficeLocation.location);
System.out.println("\n\nPaytm Object ::");
System.out.println(paytm.headOfficeLocation + "\n" + paytm.headOfficeLocation.location);
}
} |
Beta Was this translation helpful? Give feedback.
-
|
class Location { } class Address implements Cloneable { } public class UPIPaymentApps implements Cloneable { } class Driver { } |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
PART - 1:
PART - 2
Beta Was this translation helpful? Give feedback.
All reactions