• 10.30作业.


    static属性和方法如何调用:

    public class p {
        private String name;
        private int age;
        static String city ="A城";
        public p(String name,int age) {
            this.name=name;
            this.age=age;
        }
        public String getInfo() {
            return "姓名:"+this.name+",年龄:"+this.age+",城市:"+city;
        }
    }
    public class qq {
        public static void main(String args[]) {
            p p1=new p("小明",30);
            p p2=new p("小白",21);
            p p3=new p("小红",34);
            System.out.println("===分界线===");
            System.out.println(p1.getInfo());
            System.out.println(p2.getInfo());
            System.out.println(p3.getInfo());
            System.out.println("===分界线===");    
            p.city="B城";
            System.out.println(p1.getInfo());
            System.out.println(p2.getInfo());
            System.out.println(p3.getInfo());
        }
    
    }

    构造方法私有化(饿汉式)

    public class ww {
        private static ww instance=new ww();
        private ww() {
            
        }
        public static ww getInstance() {
            return instance;
        }
        public void print() {
            System.out.println("君不见");
            System.out.println("黄河之水天上来");
            System.out.println("奔流到海不复回");
            System.out.println("诗仙李白");
        }
    }
    public class ee {
        public static void main(String args[]) {
            ww s=null;
            s=ww.getInstance();
            s.print();
        }
    
    }

    空参构造自动命名(有参构造)

     

    public class aa {
        private String name;
        private static int count;
        public aa() {
            count++;
            this.name="NONAME - "+count;
            
        }
        public aa(String name) {
            this.name=name;
        }
        public String getInfo() {
            return "姓名:" +this.name;
        }
    
    }
    public class zz {
        public static void main(String args[]) {
            System.out.println(new aa().getInfo());
            System.out.println(new aa("A").getInfo());
            System.out.println(new aa("B").getInfo());
            System.out.println(new aa().getInfo());
            
        }
    
    }

    空参构造输出个数---static关键字

    public class ss {
        private String name;
        private static int count;
        public ss() {
            count++;
            System.out.println("地上有"+count+"朵花");
        }
        public String getInfo() {
            return "姓名:" +this.name;
        }
    
    }
    public class xx {
        public static void main(String args[]) {
            new ss();
            new ss();
            new ss();
            new ss();
        }
    
    }

    子父类

    abstract class TT {
        public TT() {
            this.print();
            }
        public abstract void print();
        }
    class B extends TT {
        private int x=100;
        public B(int x) {
            this.x=x;
            }
        public void print() {
            System.out.println("x - "+x);
            }
    
        }
    public class UU {
            public static void main(String args[]) {
                TT a=new B(10);
            }
    
    }
  • 相关阅读:
    关于读取Unity 配置的方案
    有关于Node.js 的最简单的概念
    小小的储备知识:有关于读取section 节点的数据
    Discuz!NT 慢慢分析之开篇Config 的实现
    Additional notes in PHP source code auditing
    Zabbix 基于WEB企业级的系统与网络信息监视系统
    Web漏洞检查工具 Wapiti
    Safe3 网站DDOS防火墙
    Web杀毒v1.0
    免费开源安全网关Untangle
  • 原文地址:https://www.cnblogs.com/gaojie77/p/7768713.html
Copyright © 2020-2023  润新知