Last active
December 23, 2021 20:29
-
-
Save agiri23/441e0815b7f9fd2384c665b760a473b2 to your computer and use it in GitHub Desktop.
Sample record class app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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