| Create a new class calledMyNewClass. |
package test;
public class MyNewClass { } |
Create a new attribute (instance variable) called var1 of type String in the MyNewClass class |
package test;
public class MyNewClass {
private String var1;
} |
Create a Constructor for your MyNewClass class which has a String parameter and assigns the value of it to the var1 instance variable. |
package test;
public class MyNewClass {
private String var1;
public MyNewClass(String para1)
{
var1 = para1;
}
} |
| Create a new method calleddoSomeThing in your class which does not return a value and has no parameters |
package test; public class MyNewClass
{
private String var1;
public MyNewClass(String para1) {
var1 = para1;
}
public void doSomeThing() {
}
} |
| Create a new method calleddoSomeThing2 in your class which does not return a value and has two parameters, a int and a Person |
package test; public class MyNewClass {
private String var1;
public MyNewClass(String para1) {
var1 = para1;
}
public void doSomeThing() {
}
public void doSomeThing2(int a, Person person) {
}
} |
| Create a new method calleddoSomeThing2 in your class which returns an int value and has three parameters, two Strings and a Person |
package test;
public class MyNewClass {
private String var1;
public MyNewClass(String para1) {
var1 = para1;
}
public void doSomeThing() {
}
public void doSomeThing2(int a, Person person) {
}
public int doSomeThing3(String a, String b, Person person) {
return 5;
}
} |
| Create a class called MyOtherClasswith two instance variables. One will store a String, the other will store a Dog. Create getter and setter for these variables. |
package test;
public class MyOtherClass {
String myvalue;
Dog dog;
public String getMyvalue() {
return myvalue;
}
public void setMyvalue(String myvalue) {
this.myvalue = myvalue;
}
public Dog getDog() {
return dog;
}
public void setDog(Dog dog) {
this.dog = dog;
}
} |