2o Ergastirio
Box
class Box {
double width;
double height;
double depth;
void sizeofBox(double x,double y, double z) {
width = x;
height = y;
depth = z;
}
//Ypologismos kai epistrofi ogou
double volume() {
return width * height * depth;
}
}
class BoxDemo2 {
public static void main(String args[]) {
Box mybox1 = new Box();
Box mybox2 = new Box();
//arxikopoiisi timwn gia kathe box
mybox1.sizeofBox(9, 8, 3);
mybox2.sizeofBox(14, 13, 12);
double vol;
//lipsi ogou tou prwtou box
vol = mybox1.volume();
System.out.println("Volume is" + vol);
//lipsi ogou tou defterou box
vol = mybox2.volume();
System.out.println("Volume is " + vol);
}
}
OverloadDemo
class OverloadDemo {
void test() {
System.out.println("No paraneters");
}
//Yperfortosi me dyo integer parametrous
void test(int a, int b) {
System.out.println("a and b: " + a + " " +b);
}
//Yperforrtosi me double parametro
void test(double a) {
System.out.println("Inside test(double) a: " + a);
}
}
class Overload {
public static void main(String atgs[]) {
OverloadDemo ob = new OverloadDemo();
int i = 88;
ob.test();
ob.test(10, 20);
ob.test(i);//Tha kalesei thn test(double).paradokso
ob.test(123.2);//Tha kalesei tin test(double)
}
}