一、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. HDU3535AreYouBusy(分组背包)

    http://acm.hdu.edu.cn/showproblem.php?pid=3535 分组背包,每一组加了以下三个限制 0 stands for the sets that should ch ...

  2. oracle客户端安装及Plsql devloper连接

    1)安装Oracle 11g 64位 2)安装32位的Oracle客户端( instantclient-basic-win32-11.2.0.1.0)下载instantclient-basic-win ...

  3. [添加用户]解决useradd 用户后没有添加用户Home目录的情况,Linux改变文件或目录的访问权限命令,linux修改用户密码

    将nobody用户添加到nogroup 组:usermod -g nogroup nobody cat /etc/passwd|grep nobodynobody:x:65534:65534:nobo ...

  4. user is not in the sudoers file.This incident will be reported

    我用普通用户ssk登陆,想让ssk成为拥有超级用户的权限的普通用户 开始提示输入密码错误 ,然后就这样了   解决方法如下: 1>.进入超级用户模式.也就是输入"su -", ...

  5. android 绘图之Canvas,Paint类

    Canvas,Paint 1.在android 绘图但中经常要用到Canvas和Paint类,Canvas好比是一张画布,上面已经有你想绘制图画的轮廓了,而Paint就好比是画笔,就要给Canvas进 ...

  6. (剑指Offer)面试题15:链表中倒数第k个结点

    题目: 输入一个链表,输出该链表中倒数第k个结点. 例如:链表中有6个结点,从头到尾依次为1,2,3,4,5,6,则该链表的倒数第3个结点为4. 链表结点定义: struct ListNode{ in ...

  7. Hibernate 与 Spring 的整合

    刚刚学习了hibernate和Spring的整合,现在来总结一下. 以实现一个功能为例,与大家分享一下整个过程. 需要实现的功能:建立一个Person类,该类包括name,sex,age,birtha ...

  8. 为DAG预留群集名称对象(CNO)

    在某些环境中,计算机帐户的创建受到限制或计算机帐户是在非默认计算机容器中创建的,则会预留群集名称对象 (CNO),然后通过为其分配权限来设置 CNO.此外,使用运行 Windows Server 20 ...

  9. git有merge时如何删除分支

    不小心增加了一个分支,并且有了merge,如何删除掉? 具有merge时不能切换分支 可以利用git stash命令 git rm controllers/InterfaceController.ph ...

  10. GLSL实现Interactive Fluid 流体【转】

    http://blog.csdn.net/a3070173/archive/2008/12/08/3479477.aspx 完成的部分: 1.流体本身的绘制和更新 未解决的部分: 1.由于采用经过抖动 ...