zoukankan      html  css  js  c++  java
  • Day10_java面向对象 static关键字详解

    static关键字详解

    package com.oop.demo07;
    
    public class Student {
        private static int age; //静态变量
        private double score;   //非静态变量
    
        public void run(){
            go();
        }
        public static void go(){
            System.out.println("hh");
        }
        public static void main(String[] args) {
            go();
    
            Student s1 = new Student();
    
            System.out.println(Student.age);
            System.out.println(s1.score);
            System.out.println(s1.age);
        }
    
    }
    
    package com.oop.demo07;
    
    public class Person {
    
        //2.赋初值~
        {
            System.out.println("匿名代码块");
        }
    
        //1.只执行一次
        static {
            System.out.println("静态代码块");
        }
    
        //3
        public Person(){
            System.out.println("构造方法!");
        }
    
        public static void main(String[] args) {
            Person person = new Person();
            System.out.println("===============");
            Person person1 = new Person();
        }
    
    
    }
    

    通过final修饰的类没有子类

    package com.oop.demo07;
    
    //静态导入包~
    import static java.lang.Math.random;
    import static java.lang.Math.PI;
    
    
    
    public class Test {
        public static void main(String[] args) {
            System.out.println(random());
            System.out.println(PI);
        }
    }
    
  • 相关阅读:
    JavaScript学习总结(十一)——Object类详解
    在mysql命令行下执行sql文件
    canal HA配置
    canal 常用配置
    canal 监控数据库表 快速使用
    HashMap 因子对性能的影响
    JVM 调优
    JVM jstat 详解
    Tomcat 异常关闭排查
    Mysql canal 监控数据变化
  • 原文地址:https://www.cnblogs.com/lemonlover/p/14043683.html
Copyright © 2011-2022 走看看