generate functionThu, 22 Dec 2022

define class with two properties name as string age as int build get and set methods. regular build class method and a copy type method use old way of get and set add copy type method

class Person{ public string name; public int age; public Person(string name, int age){ this.name = name; this.age = age; } public void setName(string name){ this.name = name; } public string getName(){ return this.name; } public void setAge(int age){ this.age = age; } public int getAge(){ return this.age; } public object Clone(){ return new Person(name, age); } } Person person = new Person("Elon", 48); person.getName() Person copyPerson = person.Clone() as Person;

Questions about programming?Chat with your personal AI assistant