一、static内部类的static方法

public class Test0719_Inner_Test {
public static void main(String[] args) {
//static内部类的static方法。。。
Outter.InnerStatic.InnerNameee();
System.out.println(Outter.InnerStatic.jjj);
System.out.println();
}
}
class Outter {
String i = "非static";
static String j = "static";
static class InnerStatic{
static String jjj = "内部类的static";
public static void InnerNameee() {
System.out.println("static内部类的static方法。。。");
//static内部类访问外部类的static成员
System.out.println(j);
//static内部类访问外部类的非static成员
System.out.println(new Outter().i);
}
}
}

运行结果:

static内部类的static方法。。。

static

非static

内部类的static

二、static内部类的非static方法

public class Test0719_Inner_Test {
public static void main(String[] args) {
//static内部类的非static方法
Outter.InnerStatic inner = new Outter.InnerStatic();
inner.InnerName();
System.out.println(inner.iii);
System.out.println();
}
}
class Outter {
String i = "非static";
static String j = "static";
static class InnerStatic{
String iii = "内部类的非static";
public void InnerName() {
System.out.println("static内部类的非static方法");
//static内部类访问外部类的static成员
System.out.println(j);
//static内部类访问外部类的非static成员
System.out.println(new Outter().i);
}
}
}

运行结果:

static内部类的非static方法

static

非static

内部类的非static

三、非static内部类的非static方法

public class Test0719_Inner_Test {
public static void main(String[] args) {
//非static内部类的非static方法…………
Outter.InnerNoStatic innerNoStatic = new Outter().new InnerNoStatic();
innerNoStatic.InnerNoName();
System.out.println(innerNoStatic.iiiNoStatic);
}
}
class Outter {
String i = "非static";
static String j = "static";
class InnerNoStatic{
int iiiNoStatic = 99776;
public void InnerNoName() {
System.out.println("非static内部类的非static方法…………");
//非static内部类访问外部类的static成员
System.out.println(Outter.j);
//非static内部类访问外部类的非static成员
System.out.println(i);
}
}
}

运行结果:

非static内部类的非static方法…………

static

非static

99776

四、综合练习

package com.acc;

public class Test0719_Inner2 {
String str = "孙洋洋"; class Text2 {
int i = 1; void m2() {
System.out.println(new Test0719_Inner2().str);
} class Text3 {
int k = 3; public void m1() {
System.out.println("m1的"+ new Test0719_Inner2().str);
}
}
} public static void main(String[] args) {
Test0719_Inner2.Text2 text2 = new Test0719_Inner2().new Text2();
text2.m2();
System.out.println(); Test0719_Inner2.Text2.Text3 text3 = new Test0719_Inner2().new Text2().new Text3();
text3.m1();
}
}

运行结果:

孙洋洋





m1的孙洋洋

五、汇总

package com.test;

public class Test0719_Inner_Test {
public static void main(String[] args) {
//static内部类的static方法。。。
Outter.InnerStatic.InnerNameee();
System.out.println(Outter.InnerStatic.jjj);
System.out.println();
//static内部类的非static方法
Outter.InnerStatic inner = new Outter.InnerStatic();
inner.InnerName();
System.out.println(inner.iii);
System.out.println();
//非static内部类的非static方法…………
Outter.InnerNoStatic innerNoStatic = new Outter().new InnerNoStatic();
innerNoStatic.InnerNoName();
System.out.println(innerNoStatic.iiiNoStatic);
}
}
class Outter {
String i = "非static";
static String j = "static";
static class InnerStatic{
String iii = "内部类的非static";
static String jjj = "内部类的static";
public void InnerName() {
System.out.println("static内部类的非static方法");
//static内部类访问外部类的static成员
System.out.println(j);
//static内部类访问外部类的非static成员
System.out.println(new Outter().i);
}
public static void InnerNameee() {
System.out.println("static内部类的static方法。。。");
//static内部类访问外部类的static成员
System.out.println(j);
//static内部类访问外部类的非static成员
System.out.println(new Outter().i);
}
} class InnerNoStatic{
int iiiNoStatic = 99776;
public void InnerNoName() {
System.out.println("非static内部类的非static方法…………");
//非static内部类访问外部类的static成员
System.out.println(Outter.j);
//非static内部类访问外部类的非static成员
System.out.println(i);
}
}
}

运行结果:

static内部类的static方法。。。

static

非static

内部类的static





static内部类的非static方法

static

非static

内部类的非static





非static内部类的非static方法…………

static

非static

99776

Java学习笔记——内部类及其调用方法的更多相关文章

  1. Java学习笔记(六)——方法

    一.方法定义 1.语法: 其中: (1) 访问修饰符:方法允许被访问的权限范围, 可以是 public.protected.private 甚至可以省略 ,其中 public 表示该方法可以被其他任何 ...

  2. 疯狂java学习笔记之面向对象(三) - 方法所属性和值传递

    方法的所属性: 从语法的角度来看:方法必须定义在类中 方法要么属于类本身(static修饰),要么属于实例 -- 到底是属于类还是属于对象? 有无static修饰 调用方法时:必须有主调对象(主语,调 ...

  3. Java学习笔记——设计模式之五.工厂方法

    水边一只青蛙在笑 --石头和水 工厂方法模式(Factory Method),定义了一个用于创建对象的接口,让实现类决定实例化哪一个类.工厂方法使一个类的实例化延迟到其子类. 这里在简单和工厂的基础上 ...

  4. 0040 Java学习笔记-多线程-线程run()方法中的异常

    run()与异常 不管是Threade还是Runnable的run()方法都没有定义抛出异常,也就是说一条线程内部发生的checked异常,必须也只能在内部用try-catch处理掉,不能往外抛,因为 ...

  5. Java学习笔记-内部类

    内部类在Android中有着大量的运用 内部类 内部类提供了更好的封装:内部类可以直接访问外部类的私有数据:匿名内部类适合那些只需要使用一次的类.非静态内部类不能拥有静态成员.内部类比外部类可以多使用 ...

  6. 1.8(java学习笔记)继承与方法的重写

    继承 在java中可以通过继承提高代码的复用率. 例如A继承了B,就可以是 例如,首先有一个类似Person,这个类中有有一些属性和方法,我们再新建一个Student类,其中有一部分属性和方法与Per ...

  7. java学习笔记之String.Split方法

    hello 大家好,好久不见,今天 我们要讨论的是java的split方法,或许你很早就知道了,但你真的知道吗? 我们来看看吧. 首先我们来看看我们最常用的split()方法也就是单个参数的方法 pu ...

  8. Java 学习笔记之 线程interrupted方法

    线程interrupted方法: interrupted()是Thread类的方法,用来测试当前线程是否已经中断. public class InterruptThread extends Threa ...

  9. Java 学习笔记之 线程interrupt方法

    线程interrupt方法: interrupt方法是用来停止线程的,但是他的使用效果并不像for+break那样,马上就停止循环. 调用interrupt()其实仅仅是在当前线程中打了一个停止标记, ...

随机推荐

  1. class-dump-z下载地址

    支持MAC.Linux.Win和iOS各个版本 http://download.csdn.net/detail/yukang1989/8414567

  2. oracle关键字使用

    v_Describe:=substr(v_Describe,0,length(v_Describe)-1); substr(目标内容,开始位置,截取长度) length(要计算的内容长度) 上述语句可 ...

  3. oracle学习 四(持续更新中)无法为表空间 MAXDATA 中的段创建 INITIAL 区

    解决建立表的时候出现的 ORA-01658: 无法为表空间 MAXDATA 中的段创建 INITIAL 区 出现这个问题是因为表空间的大小不足,可以给他扩容这样的话也会多出来一个数据文件.具体写法如下 ...

  4. UVaLive 6698 Sightseeing Bus Drivers (水题,贪心)

    题意:n个工人,有n件工作a,n件工作b,每个工人干一件a和一件b,a[i] ,b[i]代表工作时间,如果a[i]+b[j]>t,则老板要额外付钱a[i]+b[j]-t;现在要求老板付钱最少: ...

  5. hdoj 5328 Problems killer

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5328 #include<stdio.h> #include<algorithm> ...

  6. 如何让label和textblock分成两行

    http://stackoverflow.com/questions/183406/xaml-newline-in-string-attribute http://www.developerfusio ...

  7. Javascript 装载和执行(copy的感觉有很多错误。。)

    copy from:http://coolshell.cn/articles/9749.html 首先,我想说一下Javascript的装载和执行.通常来说,浏览器对于Javascript的运行有两大 ...

  8. 窥探EasyMock(1)基础使用篇

    EasyMock的应用分为5步: 1. 使用 EasyMock 生成 Mock 对象: SomeInterface mockObj = createMock(SomeInterface.class); ...

  9. JavaScript 各种遍历方式详解,有你不知道的黑科技

    http://segmentfault.com/a/1190000003968126 为了方便例子讲解,现有数组和json对象如下 var demoArr = ['Javascript', 'Gulp ...

  10. 你尽力了么===BY cloudsky

    /////////////////////////////////////////////////////////////////////////// 这是我的同事alert7在他主页上转scz的&l ...