zoukankan      html  css  js  c++  java
  • 静态(初学)

    package day01;

    public class Star {
    static String xiaoshuo; //静态变量
    String name;
    int age;
    static String zuozhe;

    static {zuozhe="jing";}//静态代码块
    //静态方法只能访问静态变量 非静态方法都可以访问(静态非静态)
    //不可以用this. 因为静态与对象没关系。
    public static String getXiaoshuo() {//静态方法
    return xiaoshuo;
    }

    public static void setXiaoshuo(String xiaoshuo) {
    Star.xiaoshuo = xiaoshuo;
    }

    public String getName() {
    return name;
    }

    public void setName(String name) {
    this.name = name;
    }

    public int getAge() {
    return age;
    }

    public void setAge(int age) {
    this.age = age;
    }
    }

    package day01;

    public class Case11 {
    public static void main(String[] args) {
    Star one=new Star();
    //one.xiaoshuo="天龙八部";//如果用one.小说,那么这个数就是通用的 two也是这个
    Star.xiaoshuo="天龙八部";
    Star two=new Star();
    System.out.println(two.xiaoshuo);
    System.out.println(two.zuozhe);



    }
    }



  • 相关阅读:
    常见的灰度发布系统规则
    golang中的路由分组
    艾森豪威尔矩阵
    列文定理
    吃狗粮定理
    mysql事务 锁
    mysql中explain优化分析
    mysql hash索引优化
    各种浏览器内核介绍
    浏览器 兼容性问题总结
  • 原文地址:https://www.cnblogs.com/worldof/p/10671458.html
Copyright © 2011-2022 走看看