• 练习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);
        }
    }

  • 相关阅读:
    转:imageNamed和dataWithContentsOfFile的区别
    [内存管理实践 之 1]在返回按钮中,释放内存
    转:当程序崩溃的时候怎么办 Part2
    iOS 内存管理,我们需要一套切实可行的实践指导书,而不是理论指导书
    转 iOS程序中调用系统自带应用(短信,邮件,浏览器,地图,appstore,拨打电话)
    iOS笔记:内存管理
    转:【图文教程】创建Xcode自定义模板
    判断两个数的大小,返回其中的大者/小者
    iOS全局变量与属性的内存管理
    UIImage 详解
  • 原文地址:https://www.cnblogs.com/zr1636050087/p/7768664.html
Copyright © 2020-2023  润新知