In: Computer Science
Create java class with name MyClass1
Instructions for MyClass1
For this portion of the assignment you will need to create a java class of your own to model some objects in the real world or your own imagination. your classes should have at least three instances variables, accessor and mutator methods for each of those instance variables, one constructor method of any type, as well as an overridden toString method that will display every field value as part of a String. Use meaningful identifiers for the name of class.
Demonstrate that your class work appropriately by creating instances of each in the MainClass class which contains a main method
class MyClass {
private String name;
private String Id;
private String address;
public MyClass(String aName, String aId, String
aAddress) {
super();
name = aName;
Id = aId;
address = aAddress;
}
public String getName() {
return name;
}
public void setName(String aName) {
name = aName;
}
public String getId() {
return Id;
}
public void setId(String aId) {
Id = aId;
}
public String getAddress() {
return address;
}
public void setAddress(String aAddress) {
address = aAddress;
}
@Override
public String toString() {
return "MyClass [name=" + name + ",
Id=" + Id + ", address=" + address + "]";
}
}
public class MainClass {
public static void main(String[] args) {
MyClass m1 = new MyClass("Uday",
"1", "Hyderabad");
MyClass m2 = new
MyClass("Koteswari", "2", "Secundrabad");
System.out.println(m1);
System.out.println(m2);
}
}
Note : Please comment below if you have concerns. I am here to help you
If you like my answer please rate and help me it is very Imp for me