内部类的大概介绍
内部 类 内部 类有二种:成员式的(像外部类的属性)和区域式的(像外部类中的方法中的变量)。 一、成员式 该中的 内部 类有可分为:类级别(static声明的 内部 类)和对象级别 InnerClasses.java package innerClass; public class InnerClasses { private
内部类
内部类有二种:成员式的(像外部类的属性)和区域式的(像外部类中的方法中的变量)。
一、成员式
该中的内部类有可分为:类级别(static声明的内部类)和对象级别
InnerClasses.java
package innerClass;
public class InnerClasses {
private static String staticAttribute = " Outter class static attribute ";
private String instantAttribute = "Outter class instant ";
//对象级别的方法
public void instantMethod(){
System.out.println("Outter class instant method ");
}
//类级别的方法
public static void staticMethod(){
System.out.println("Outter class static method");
}
//类级别的内部类
/**
* 该内部类中的方法 必须方位外部类的类级别的属性和方法,否则不错。
* 如:只能访问外部类的staticAttribute属性和staticMethod()方法
* */
public static class StaticInnerClass{
public StaticInnerClass(){
System.out.println("static Inner class ");
}
public void access(){
System.out.println(staticAttribute);
staticMethod();
}
}
//对象级别的内部类
/**
* 该内部类可以访问外部类中的所有的方法和属性
* */
public class InstantInnerClass{
public InstantInnerClass(){
System.out.println("Instant Inner Class");
}
public void access(){
System.out.println(instantAttribute);
staticMethod();
}
}
}
内部类的访问方式:
1、类级别的内部类 通过外部类的类名访问内部类
2、对象级别的内部类,必须通过外部类的对象访问
package innerClass;
public class TestClass {
public void callStaticInnerClass(){
//用外部类的类名来访问
InnerClasses.StaticInnerClass sic
= new InnerClasses.StaticInnerClass();
sic.access();
}
public void callInstantInnerClass(){
//访问对象级别的内部类需要 外部类的对象才能访问
//声明一个外部类的兑现ic
InnerClasses ic = new InnerClasses();
//对象访问 对象级别的内部类
InnerClasses.InstantInnerClass iic ;
iic = ic.new InstantInnerClass();
}
}
抽象内部类
Static修饰的内部抽象类 可以通过外部类的类名 访问到,被其他类继承
成员级别的内部类抽象类,只能被该外部类中的其他的内部类继承
二、区域式
该中的内部类可分为:变量级别的和匿名级别
变量级别的内部类即声明在方法中的类。该内部类不适用。
匿名内部类。即没有类名的内部类。
package innerClass;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class AnonymousInnerClass {
public static void main(String[] args){
Frame f = new Frame("Anonymous Inner Class Example ");
//该方法的参数是一个匿名内部类的应用
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
f.setSize(200,200);
f.setVisible(true);
}
}

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Users may have seen the term wapi when using the Internet, but for some people they definitely don’t know what wapi is. The following is a detailed introduction to help those who don’t know to understand. What is wapi: Answer: wapi is the infrastructure for wireless LAN authentication and confidentiality. This is like functions such as infrared and Bluetooth, which are generally covered near places such as office buildings. Basically they are owned by a small department, so the scope of this function is only a few kilometers. Related introduction to wapi: 1. Wapi is a transmission protocol in wireless LAN. 2. This technology can avoid the problems of narrow-band communication and enable better communication. 3. Only one code is needed to transmit the signal

Pubg, also known as PlayerUnknown's Battlegrounds, is a very classic shooting battle royale game that has attracted a lot of players since its popularity in 2016. After the recent launch of win11 system, many players want to play it on win11. Let's follow the editor to see if win11 can play pubg. Can win11 play pubg? Answer: Win11 can play pubg. 1. At the beginning of win11, because win11 needed to enable tpm, many players were banned from pubg. 2. However, based on player feedback, Blue Hole has solved this problem, and now you can play pubg normally in win11. 3. If you meet a pub

i5 is a series of processors owned by Intel. It has various versions of the 11th generation i5, and each generation has different performance. Therefore, whether the i5 processor can install win11 depends on which generation of the processor it is. Let’s follow the editor to learn about it separately. Can i5 processor be installed with win11: Answer: i5 processor can be installed with win11. 1. The eighth-generation and subsequent i51, eighth-generation and subsequent i5 processors can meet Microsoft’s minimum configuration requirements. 2. Therefore, we only need to enter the Microsoft website and download a "Win11 Installation Assistant" 3. After the download is completed, run the installation assistant and follow the prompts to install Win11. 2. i51 before the eighth generation and after the eighth generation

After updating to the latest win11, many users find that the sound of their system has changed slightly, but they don’t know how to adjust it. So today, this site brings you an introduction to the latest win11 sound adjustment method for your computer. It is not difficult to operate. And the choices are diverse, come and download and try them out. How to adjust the sound of the latest computer system Windows 11 1. First, right-click the sound icon in the lower right corner of the desktop and select "Playback Settings". 2. Then enter settings and click "Speaker" in the playback bar. 3. Then click "Properties" on the lower right. 4. Click the "Enhance" option bar in the properties. 5. At this time, if the √ in front of "Disable all sound effects" is checked, cancel it. 6. After that, you can select the sound effects below to set and click

PyCharm is a powerful Python integrated development environment with rich functions and tools that can greatly improve development efficiency. Among them, the replacement function is one of the functions frequently used in the development process, which can help developers quickly modify the code and improve the code quality. This article will introduce PyCharm's replacement function in detail, combined with specific code examples, to help novices better master and use this function. Introduction to the replacement function PyCharm's replacement function can help developers quickly replace specified text in the code

Many users have printer drivers installed on their computers but don't know how to find them. Therefore, today I bring you a detailed introduction to the location of the printer driver in the computer. For those who don’t know yet, let’s take a look at where to find the printer driver. When rewriting content without changing the original meaning, you need to The language is rewritten to Chinese, and the original sentence does not need to appear. First, it is recommended to use third-party software to search. 2. Find "Toolbox" in the upper right corner. 3. Find and click "Device Manager" below. Rewritten sentence: 3. Find and click "Device Manager" at the bottom 4. Then open "Print Queue" and find your printer device. This time it is your printer name and model. 5. Right-click the printer device and you can update or uninstall it.

Dogecoin is a cryptocurrency created based on Internet memes, with no fixed supply cap, fast transaction times, low transaction fees, and a large meme community. Uses include small transactions, tips, and charitable donations. However, its unlimited supply, market volatility, and status as a joke coin also bring risks and concerns. What is Dogecoin? Dogecoin is a cryptocurrency created based on internet memes and jokes. Origin and History: Dogecoin was created in December 2013 by two software engineers, Billy Markus and Jackson Palmer. Inspired by the then-popular "Doge" meme, a comical photo featuring a Shiba Inu with broken English. Features and Benefits: Unlimited Supply: Unlike other cryptocurrencies such as Bitcoin

2024 is the first year of AI mobile phones. More and more mobile phones integrate multiple AI functions. Empowered by AI smart technology, our mobile phones can be used more efficiently and conveniently. Recently, the Galaxy S24 series released at the beginning of the year has once again improved its generative AI experience. Let’s take a look at the detailed function introduction below. 1. Generative AI deeply empowers Samsung Galaxy S24 series, which is empowered by Galaxy AI and brings many intelligent applications. These functions are deeply integrated with Samsung One UI6.1, allowing users to have a convenient intelligent experience at any time, significantly improving the performance of mobile phones. Efficiency and convenience of use. The instant search function pioneered by the Galaxy S24 series is one of the highlights. Users only need to press and hold
