• 练习8(图片题)


    1. 

    package cn.ch.w;
    
    public class Person {
        private String name;
        private static int count;
        public Person()
        {
            count++;
            System.out.println("产生了"+count+"个小蘑菇。");
        }
        public String getInfo()
        {
            return "姓名:"+this.name;
        }
    }
    package cn.ch.w;
    
    public class StaticDemo {
        public static void main(String args[])
        {
            new Person();
            new Person();
            new Person();
            new Person();
            new Person();
        }
    
    }
    
    

    
    

     2.

    package cn.ch.w;
    
    public class Person {
        private String name;
        private static int count;
        public Person()
        {
            count++;
            this.name="xixixi-"+count;
        }
        public Person(String name)
        {
            this.name=name;
        }
        public String getInfo()
        {
            return"你谁?"+this.name;
        }
    
    }
    package cn.ch.w;
    
    public class StaticDemo {
        public static void main(String args[])
        {
            System.out.println(new Person().getInfo());
            System.out.println(new Person("A").getInfo());
            System.out.println(new Person("B").getInfo());
            System.out.println(new Person().getInfo());
        }
    
    }

    3.

    package cn.ch.w;
    
    public class Single {
        private static Single instance=new Single();
        private Single()
        {
            
        }
        public static Single getInstance()
        {
            return instance;
        }
        public void print()
        {
            System.out.println("你喜欢吃蘑菇吗!!");
        }
    }
    package cn.ch.w;
    
    public class SingleDemo {
        public static void main(String args[])
        {
            Single s=null;
            s = Single.getInstance();
            s.print();
        }
    
    }

     4.

    package cn.ch.w;
    
    public class Person {
        private String name;
        private int age;
        static String city="捷克共和国";
        public Person(String name,int age)
        {
            this.name=name;
            this.age=age;
        }
        public String getInfo()
        {
            return "小蘑菇你叫啥?"+this.name+",多大啦:"+this.age+",住在哪里啊"+city;
        }
    }
    package cn.ch.w;
    
    public class StaticDemo {
        public static void main(String arges[])
        {
            Person per1=new Person("金针菇",21);
            Person per2=new Person("杏鲍菇",22);
            Person per3=new Person("茶树菇",23);
            System.out.println("------隐姓埋名前------");
            System.out.println(per1.getInfo());
            System.out.println(per2.getInfo());
            System.out.println(per3.getInfo());
            System.out.println("------隐姓埋名后------");
            Person.city="中华人名共和国";
            System.out.println(per1.getInfo()5.);
            System.out.println(per2.getInfo());
            System.out.println(per3.getInfo());
            
        }
    
    }

    5.

    package cn.ch.w;
    
    public class A {
        public A()
        {
            this.print();
        }
        public void print() {
        }
    
    }
    class B extends A{
        private int x=100;
        public B(int x){
            this.x=x;
        }
        public void printf()
        {
            System.out.println("x= "+x);
            
        }
    }
    package cn.ch.w;
    
    public class TestJava {
        public static void main(String args[])
        {
            A a=new B(10);
        }
    }

  • 相关阅读:
    Gradle 3.0 + 打包android module 为aar
    Android SELinux
    Mac OS X 修改文件创建时间、修改时间 + zip 过滤临时文件
    Android 应用运行期间系统配置(系统语言、字体大小等)改变引发的问题修改
    Docker 指令
    Ubuntu-spark安装
    Highcharts 二种导出方式
    使用Storyboard 创建ViewController
    数据持久化-Plist
    模拟器常用快捷键
  • 原文地址:https://www.cnblogs.com/zr1636050087/p/7768664.html
Copyright © 2020-2023  润新知