Skip to content

Instantly share code, notes, and snippets.

@agiri23
Last active December 23, 2021 20:29
Show Gist options
  • Save agiri23/441e0815b7f9fd2384c665b760a473b2 to your computer and use it in GitHub Desktop.
Save agiri23/441e0815b7f9fd2384c665b760a473b2 to your computer and use it in GitHub Desktop.
Sample record class app
public class SampleRecordClass {
record Country(String name,String capital){}
public static void main(String[] args) {
Country firstCountry = new Country("Netherlands","Amsterdam");
Country secondCountry = new Country("Germany","Berlin");
System.out.println("First country object is " + firstCountry);
System.out.println("Second country object is " + secondCountry);
System.out.println("Check if both objects equal" + firstCountry.equals(secondCountry));
// Copying object using attribute method of existing records object
Country countryClone = new Country(firstCountry.name,firstCountry.capital);
System.out.println("country clone object" + countryClone);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment