public class Test
{
public static void main(String[] args)
{
Human me = new Human("Vamei");
me.drinkWater(0.3);
}
}
class Human
{
/**
* inner class
*/
private class Cup
{
public void useCup(double w)
{
this.water = this.water - w;
}
public double getWater()
{
return this.water;
}
private double water = 1.0;
}
/**
* constructor
*/
public Human(String n)
{
this.myCup = new Cup();
this.name = n;
}
public void drinkWater(double w)
{
myCup.useCup(w);
System.out.println(myCup.getWater());
}
private Cup myCup;
private String name;
}
public class Test
{
public static void main(String[] args)
{
Human me = new Human("Vamei");
me.drinkWater(0.3);
Human.Cup soloCup = me.new Cup(); // be careful here
}
}
class Human
{
/**
* inner class
*/
class Cup
{
public void useCup(double w)
{
this.water = this.water - w;
}
public double getWater()
{
return this.water;
}
private double water = 1.0;
}
/**
* constructor
*/
public Human(String n)
{
this.myCup = new Cup();
this.name = n;
}
public void drinkWater(double w)
{
myCup.useCup(w);
System.out.println(myCup.getWater());
}
private Cup myCup;
private String name;
}
public class Test
{
public static void main(String[] args)
{
Human me = new Human("Vamei");
Human him = new Human("Jerry");
Human.Cup myFirstCup = me.new Cup();
Human.Cup mySecondCup = me.new Cup();
Human.Cup hisCup = him.new Cup();
System.out.println(myFirstCup.whosCup());
System.out.println(mySecondCup.whosCup());
System.out.println(hisCup.whosCup());
}
}
class Human
{
/**
* inner class
*/
class Cup
{
public String whosCup()
{
return name; // access outer field
}
}
/**
* constructor
*/
public Human(String n)
{
this.name = n;
}
public void changeName(String n)
{
this.name = n;
}
private String name;
}
Vamei Vamei Jerry
public class Test
{
public static void main(String[] args)
{
Human.Mongolian him = new Human.Mongolian();
him.Shout();
}
}
class Human
{
/**
* nested class
*/
static class Mongolian
{
public void Shout()
{
System.out.println("Oh...Ho...");
}
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有