public class Test
{
public static void main(String[] args)
{
Human aPerson;
aPerson = new Cup();
}
}
class Human
{
/**
* constructor
*/
public Human(int h)
{
this.height = h;
}
/**
* accessor
*/
public int getHeight()
{
return this.height;
}
/**
* mutator
*/
public void growHeight(int h)
{
this.height = this.height + h;
}
private int height;
}
class Cup
{
public void addWater(int w)
{
this.water = this.water + w;
}
public void drinkWater(int w)
{
this.water = this.water - w;
}
private int water = 0;
}
found : Cup
required: Human
aPerson = new Cup();
^
1 error
public class Test
{
public static void main(String[] args)
{
int a;
a = (int) 1.23; // narrowing conversion
System.out.println(a);
}
}
public class Test
{
public static void main(String[] args)
{
int a = 3;
double b;
b = a; // widening conversion
System.out.println(a);
}
}
public class Test
{
public static void main(String[] args)
{
Cup aCup;
BrokenCup aBrokenCup = new BrokenCup();
aCup = aBrokenCup; // upcast
aCup.addWater(10); // method binding
}
}
class Cup
{
public void addWater(int w)
{
this.water = this.water + w;
}
public void drinkWater(int w)
{
this.water = this.water - w;
}
private int water = 0;
}
class BrokenCup extends Cup
{
public void addWater(int w)
{
System.out.println("shit, broken cup");
}
public void drinkWater(int w)
{
System.out.println("om...num..., no water inside");
}
}
shit, broken cup
public class Test
{
public static void main(String[] args)
{
Human guest = new Human();
BrokenCup hisCup = new BrokenCup();
guest.drink(hisCup, 10);
}
}
class Human
{
void drink(Cup aCup, int w)
{
aCup.drinkWater(w);
}
}
shit, no water inside
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有