Uploaded by Londe Thomas

Classes Objects examples

advertisement
public
int
int
int
class productClass{
value1;
value2;
product;
public productClass(int num1, int num2, int iProduct){
value1 = num1;
value2 = num2;
product = iProduct;
}
public void getProduct(int digit1, int digit2){
value1 = digit1;
value2 = digit2;
}
public int outputProduct(){
product = value1 * value2;
return product;
}
}
---------------------------------------------------------------public class testProduct{
public static void main(String[] args){
productClass proObject = new productClass(0,0,0);
proObject.getProduct(5,8);
System.out.println(proObject.outputProduct());
}
}
public class MyName{
String Name;
public MyName(String NewName){
Name = NewName;
}
public void getName(String FName){
Name = FName;
}
public String writeName(){
return Name;
}
}
------------------------------------------------------------public class testName{
public static void main(String[] args){
MyName nameObject = new MyName("Adam");
nameObject.getName("Gregory");
System.out.println(nameObject.writeName());
}
}
public
int
int
int
class Math{
num;
value;
sum;
public Math(int digit1, int digit2){
digit1 = num;
digit2 = value;
}
public int inputSum(int number1, int number2){
//int sum;
sum = number1 + number2;
return sum;
}
public void getSum(){
System.out.println(sum);
}
}
------------------------------------------------------------public class TestMath{
public static void main(String[] args){
Math TestMath = new
Math();
TestMath.inputSum(4,6);
TestMath.getSum();
}
}
Download