java学习(66):局部类内方法访问
生活随笔
收集整理的這篇文章主要介紹了
java学习(66):局部类内方法访问
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
定義一個類
package com.zx; public class NotebookComputer {private int num; private CPU cpu;public String fromIntoBit(){ class CPU2{// 局部內部類public String countBit(int num){return Integer.toBinaryString(num);}}return (new CPU2().countBit(num));}/**** 普通內部類*/ private final class CPU{}public NotebookComputer(int num){this.num = num;if(cpu == null)cpu = new CPU();}}定義測試類
package com.zx;public class TestInnerClass {public static void main(String[] args) { // // 創建一個外部類 // NotebookComputer com = new NotebookComputer(); // // 聲明一個內部類 // NotebookComputer.CPU cpu; // // // 通過外部類的實例創建一個內部類對象 // cpu = com.new CPU(); // // String bitStr = cpu.countBit(11); // System.out.println(bitStr);NotebookComputer com = new NotebookComputer(9);System.out.println(com.fromIntoBit());// System.out.println(com.fromIntoBit()); // // /* 內部靜態類的創建*/ // NotebookComputer.VideoCard vc = new NotebookComputer.VideoCard(); // // vc.showMessage("我是內部靜態類");} }運行結果
總結
以上是生活随笔為你收集整理的java学习(66):局部类内方法访问的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: bootstrap 合并菜单_Boots
- 下一篇: 东芝笔记本linux系统安装驱动,最详实