zoukankan      html  css  js  c++  java
  • “静态内部类” 与 “外部类” 之间的相互调用

    本文主要对 “静态内部类” 与 “外部类” 之间的相互调用 进行适当的实例+测试

    一,代码

    package com.wqb.staticclass;
    
    public class TestMain {
    
    	public static void main(String[] args) {
    		OutsideClass.InsideClass.staticMethod("OutsideClass.InsideClass.staticMethod(methodName)");
    		new OutsideClass().outsideMethod("【一般类的非静态方法】 调用");
    		new OutsideClass.InsideClass();
    		
    		new OutsideClass.InsideClass().insideMethod("【一般类的静态方法】 调用");
    		new TestMain().test();
    	}
    	
    	public void test(){
    		OutsideClass.InsideClass.staticMethod(new String("test()"));
    		new OutsideClass.InsideClass().insideMethod("【一般类的一般方法】 调用");
    	}
    }
    
    class OutsideClass{
    	static class InsideClass{
    		
    		// 静态内部类的构造方法
    		public InsideClass(){
    			System.out.println("静态内部类的【构造函数】");
    		}
    		
    		public static void staticMethod(String methodName){
    			System.out.println(methodName + "调用静态内部类 的 静态方法。——————可行!!!");
    			
    			new OutsideClass().outsideMethod("【静态内部类 的 静态方法】 调用");
    			new OutsideClass.InsideClass().insideMethod("【静态内部类 的 静态方法】 调用");
    		}
    		
    		public void insideMethod(String who){
    			System.out.println(who + "静态内部类 中,非静态方法。——————可行!!!");
    		}
    	}
    	
    	public void outsideMethod(String who){
    		System.out.println(who + "外部类 的 非静态方法。——————可行!!!");
    	}
    }
    

    二、运行结果

     1 OutsideClass.InsideClass.staticMethod(methodName)调用静态内部类 的 静态方法。——————可行!!!
     2 【静态内部类 的 静态方法】 调用外部类 的 非静态方法。——————可行!!!
     3 静态内部类的【构造函数】
     4 【静态内部类 的 静态方法】 调用静态内部类 中,非静态方法。——————可行!!!
     5 【一般类的静态方法】 调用外部类 的 非静态方法。——————可行!!!
     6 静态内部类的【构造函数】
     7 静态内部类的【构造函数】
     8 【一般类的静态方法】 调用静态内部类 中,非静态方法。——————可行!!!
     9 test()调用静态内部类 的 静态方法。——————可行!!!
    10 【静态内部类 的 静态方法】 调用外部类 的 非静态方法。——————可行!!!
    11 静态内部类的【构造函数】
    12 【静态内部类 的 静态方法】 调用静态内部类 中,非静态方法。——————可行!!!
    13 静态内部类的【构造函数】
    14 【一般类的一般方法】 调用静态内部类 中,非静态方法。——————可行!!!
  • 相关阅读:
    python邮件之附件
    python3.5之smtp
    一台Linux上搭建两个tomcat
    mysql 初探(一)
    python监视mysql最大连接数
    P3658 [USACO17FEB]Why Did the Cow Cross the Road III P cdq分治
    P4793 [AHOI2008]矩形藏宝地 cdq分治 线段树
    P2487 [SDOI2011]拦截导弹 线段树 cdq分治
    P3157 [CQOI2011]动态逆序对 cdq分治
    P4169 [Violet]天使玩偶/SJY摆棋子 cdq分治
  • 原文地址:https://www.cnblogs.com/bridgestone29-08/p/6472804.html
Copyright © 2011-2022 走看看