#1. What is the difference between static nested class and inner class?
Static nested class: Static Nested Class is an inner class declared as static (static), which can be instantiated without relying on external class instances.
Inner class: It needs to be instantiated after the external class is instantiated before it can be instantiated. Its syntax looks quite weird. (Recommended study: java interview questions)
2. Where in the following code will compilation errors occur?
class Outer { class Inner { } public static void foo() { new Inner(); } public void bar() { new Inner(); } public static void main(String[] args) { new Inner(); } }
Note: The creation of non-static inner class objects in Java depends on its outer class objects. In the above interview questions, the foo and main methods are both static methods. There is no this in the static method, that is It says that there is no so-called outer class object, so inner class objects cannot be created. If you want to create an inner class object in a static method, you can do this:
new Outer().new Inner();
Reflection in Java
Tell me about your understanding of reflection in Java
Reflection in Java is first able to obtain the bytecode of the reflection class in Java. There are three ways to obtain the bytecode:
Class.forName(className).
Class name.class.
this.getClass().
Then the methods, variables, constructors, etc. in the bytecode are mapped into corresponding Method, Field, Constructor and other classes. These classes provide a wealth of methods that can be used by us.
The above is the detailed content of Java internal classes and reflection interview questions. For more information, please follow other related articles on the PHP Chinese website!

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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 English version
Recommended: Win version, supports code prompts!

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