11

  1 package cn.lyhh;
  2 class Person{
  3     private String name;
  4     private int age;
  5     static String city =  "A城";
  6     public Person(String name,int age) {
  7         this.name = name;
  8         this.age = age;
  9     }
 10     public String getInfo() {
 11         return "姓名:" + this.name + ",年龄:" + this.age + ",城市:" + city;
 12     }
 13 }
 14 public class L {
 15     public static void main(String[] args) {
 16         Person per1 = new Person("张三",30);
 17         Person per2 = new Person("李四",31);
 18         Person per3 = new Person("王五",30);
 19         System.out.println("======修改信息之前======");
 20         System.out.println(per1.getInfo());
 21         System.out.println(per2.getInfo());
 22         System.out.println(per3.getInfo());
 23         System.out.println("======修改信息之后======");
 24         Person.city = "B城";
 25         System.out.println(per1.getInfo());
 26         System.out.println(per2.getInfo());
 27         System.out.println(per3.getInfo());
 28         
 29     }
 30 }
 31 
 32 
 33 
 34 
 35 
 36 package cn.lyhh;
 37 class La{
 38     private static La instance = new La();
 39     private La() {
 40     }
 41     public static La getInstance() {
 42         return instance;
 43     }
 44     public void print() {
 45         System.out.println("hello world!!!");
 46     }
 47 }
 48 public class L {
 49     public static void main(String[] args) {
 50         La s = null;
 51         s = La.getInstance();
 52         s.print();
 53     }
 54 
 55 }
 56 
 57 
 58 
 59 package cn.mxl;
 60 class Person{
 61     private String name;
 62     private static int count;
 63     public Person() {
 64         count++;
 65         this.name = "NONAME - " + count;
 66     }
 67     public Person(String name) {
 68         this.name = name;
 69     }
 70     public String getInfo() {
 71         return "姓名:" + this.name;
 72     }
 73 }
 74 public class Ly{
 75     public static void main(String[] args) {
 76         System.out.println(new Person().getInfo());
 77         System.out.println(new Person("A").getInfo());
 78         System.out.println(new Person("B").getInfo());
 79         System.out.println(new Person().getInfo());
 80     }
 81 
 82 }
 83 
 84 
 85 
 86 
 87 
 88 package cn.mxl;
 89 class Person{
 90     private String name;
 91     private static int count;
 92     public Person() {
 93         count++;
 94         System.out.println("产生了" + count + "个实例化");
 95     }
 96     public String getInfo() {
 97         return "姓名:" + this.name;
 98     }
 99 }
100 public class Y {
101     public static void main(String[] args) {
102         new Person();
103         new Person();
104         new Person();
105         new Person();
106         new Person();
107     }
108 }
109 
110 
111 
112 package cn.lyh;
113 
114 public class MXL {
115     public static void main(String[] args) {
116         for (int x=0;x<args.length;x++) {
117             System.out.println(args[x] + "");
118         }
119     }
120 }

 

转载于:https://www.cnblogs.com/a718204806/p/8057429.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值