zoukankan      html  css  js  c++  java
  • static修饰java内部运行顺序

    package com.demo01;
    
    
    public class Static extends demo{
    
    	/**
    	 * @param args
    	 */
    	private static String str = "这是静态变量-------";
    	private String name;
    	int b = 20;
    	private static int a= 100;
    	
    	//静态的重写父类的静态方法
    	public static void eat(){
    		System.out.println("子类重写的静态方法-====");
    	}
    	public void display(){
    		super.eat();
    	}
    	
    	
    	public static void staticMethod(){
    		System.out.println("这是静态的方法---");
    		//System.out.println(this.a+this.b);在静态方法中不能使用this关键字
    		//System.out.println(b);不能直接访问非static变量和方法
    		System.out.println(Static.a);
    	}
    	
    	public Static() {
    		System.out.println("这是选择器的--------");
    	}
    	static{
    		System.out.println("这是静态代码块1------");
    	}
    	static{
    		System.out.println("这是静态代码块2------");
    	}
    	public static void study(){
    		System.out.println("这是静态的方法-------");
    	}
    
    /*
     *       这是静态代码块------
            这是选择器的--------
            这是静态变量-------
            这是静态的方法-------
            
            
            静态的代码块在代码加载时就执行,且只加载一次。其他从上到下依次执行
            静态方法必须实例化
     */
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		Static st  =  new Static();
    		System.out.println(Static.str);
    		Static.study();
    		Static st1  =  new Static();
    		Static st2  =  new Static();
    		
    		Static t = new Static();
    		System.out.println(t.b);
    		Static.staticMethod();
    		System.out.println(Static.a);
    		
    		t.display();
    		t.eat();
    
    	}
    
    
    }
    class  demo{
    	
    	protected static int num = 52;
    	public static void eat(){
    		System.out.println("父类的静态方法-------");
    	}
    }
    

      

  • 相关阅读:
    通知
    KVO详解
    KVC详解
    KVC/KVO总结
    结构体Struct
    检测文件(夹)大小
    NSFileHandle&&NSFileManage
    ***NSFileManager
    获取文件扩展名
    MySql数据库_03
  • 原文地址:https://www.cnblogs.com/nn369/p/8010544.html
Copyright © 2011-2022 走看看