Você está na página 1de 5

class Box{

double width;
double hieght;
double depth;
}
class BoxDemo1{
public static void main(String ard[]){
Box mybox=new Box();
double vol;
mybox.width=10;
mybox.hieght=20;
mybox.depth=15;
vol=mybox.width*mybox.hieght*mybox.depth;
System.out.println("volume is "+vol);
}}
class Box{
double width;
double hieght;
double depth;
}
class BoxDemo2{
public static void main(String ard[]){
Box mybox1=new Box();
Box mybox2=new Box();
double vol;
mybox1.width=10;
mybox1.hieght=20;
mybox1.depth=15;
mybox2.width=3;
mybox2.hieght=6;
mybox2.depth=9;
vol=mybox1.width*mybox1.hieght*mybox1.depth;
System.out.println("volume for mybox1 is "+vol);
vol=mybox2.width*mybox2.hieght*mybox2.depth;
System.out.println("volume for mybox2 is "+vol);
}}
class Box{
static double width;
static double hieght;
static double depth;
static void volume(){
System.out.println("volume is ");
System.out.println(width*hieght*depth);
}
}

class BoxDemo3{
public static void main(String ard[]){
Box mybox1=new Box();
//Box mybox2=new Box();
double vol;
mybox1.width=50;
mybox1.hieght=20;
mybox1.depth=15;
mybox1.volume();
//mybox2.width=3;
//mybox2.hieght=6;
//mybox2.depth=9;
//mybox2.volume();
}}
class Box{
double width;
double hieght;
double depth;
double volume(){
return width*hieght*depth;
}
void setDim(double w,double h,double d){
width=w;
hieght=h;
depth=d;}
}
class BoxDemo5{
public static void main(String ard[]){
Box mybox1=new Box();
Box mybox2=new Box();
double vol;
mybox1.setDim(10,20,15);
mybox2.setDim(3,6,9);
vol=mybox1.volume();
System.out.println("the volume is "+vol);
vol=mybox2.volume();
System.out.println("the volume is "+vol);
}}
class Box{
double width;
double hieght;
double depth;
Box(){
System.out.println("constructing Box");
width=10;
2

hieght=10;
depth=10;
}
double volume(){
return width*hieght*depth;
}}
class BoxDemo6{
public static void main(String ard[]){
Box mybox1=new Box();
Box mybox2=new Box();
double vol;
vol=mybox1.volume();
System.out.println("volume is "+vol);
vol=mybox2.volume();
System.out.println("the volume is "+vol);
}}
class Overload {
void test(){
System.out.println("no parameter");
}
void test(int a,int b ){
System.out.println("a="+a+" b="+b);}
void test(double a ){
System.out.println("a="+a*a);}}
class Rr{
public static void main(String ard[])
{
Overload ol=new Overload();
double ee;
ol.test();
ol.test(10);
ol.test(10,20);
ol.test(33.4);
}}
class Box{
double width;
double hieght;
double depth;
Box (double w,double h,double d){
width=w;
hieght=h;
depth=d;
}
Box (double w,double h){
this (w,h,1);
double s=this.volume();
3

System.out.println("volume isfffff "+s);


}
Box(){
System.out.println("constructing Box");
width=-1;
hieght=-1;
depth=-1;
}
Box (double len){
width=hieght=depth=len;
}
double volume(){
return width*hieght*depth;
}
}
class Bo6{
public static void main(String ard[]){
Box mybox1=new Box(10,20,15);
Box mybox2=new Box(22,10);
Box mycube=new Box(7);
double vol;
vol=mybox1.volume();
System.out.println("volume is "+vol);
vol=mybox2.volume();
System.out.println("the volume is "+vol);
vol=mycube.volume();
System.out.println("the volume is "+vol);
}}
class Overload {
void test(){ System.out.println("no parameter");}
void test(int a,int b ){
System.out.println("a="+a+" b="+b);}
void test(double a ){
System.out.println("a="+a*a);
}}
class Rr{
public static void main(String ard[])
{
Overload ol=new Overload();
double ee;
ol.test();
ol.test(10);
ol.test(10,20);
ol.test(33.4);
}}

class A {
int i=11,j=11;
A(int a,int b){
i=a;
j=b;
}
void show(){
System.out.println("i,j"+i+j);
}}
class B extends A {
int k;
B(int a,int b,int c){
super(a,b);
k=c;}
//overriden
void show(){
//super.show();
System.out.println("k"+k);
}}
class Over1{
public static void main (String args[]){
B bb=new B(1,2,3);
A aa=new A(1,2);
bb.show();
aa.show();
}}

Você também pode gostar