• 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 }

  • 相关阅读:
    JavaScript.对象分类
    基于NDK的Android防破解& Android防破解 【转载】
    C++ 关键字——friend【转载】
    Python基础教程学习笔记:第二章 列表和元组
    Android安装器学习笔记(一)
    Python基础教程学习笔记:第一章 基础知识
    Android重写HorizontalScrollView仿ViewPager效果
    C语言realloc,malloc,calloc的区别【转载】
    Objective-C 协议和运行时检查方法、类是否存在
    下拉刷新 上拉更多 支持ListView GridView WebView【转载】
  • 原文地址:https://www.cnblogs.com/a718204806/p/8057429.html
Copyright © 2020-2023  润新知