Z: hero, I'm back.
M: I understand the internal class. In fact, the design model involves a lot of basic knowledge. What project engineering experience does a student have? You are very motivated. Let's talk about internal classes, especially static internal classes in singleton mode. Let's get started; M. When is the internal class?
In short, there are classes in the class.
M: What is the difference between a static internal class and a common internal class?
A common internal class can be understood as a common method of an external class. You need to create an external object. To put it bluntly, a common class belongs to an object.
Outclass. innerclass OBJ = outclassinstance. New innerclass ();
Static internal classes can be understood as static methods. They belong to the entire class and do not need to create external objects.
AAA. staticinner in = new AAA. staticinner M: Can a common internal class have a static attribute? Why?
No. I don't know.
Success .,
M:External classes can access all methods and attributes of internal classes, including private methods and attributes.. ?
Yes
M: Do you understand the code you wrote yesterday? I'm tempted to tell you the answer. You are not sorry yet
Z:
Private Static class singletonholder
{
Private Static Singleton instance = new Singleton ();
}
Public static Singleton getinstance ()
{
Return singletonholder. instance;
}
Z: Let me try to summarize it.
Internal classes are set to private. To avoid using classes other than the Department classes,
First
Singleton. getinstance ();
Because getinstance is static, you must access the static attribute,
Static attributes can only be in static internal classes.
M: You have the potential to become a good engineer.
Z: Actually, I am not familiar with internal classes.
M: What do you think about the singleton mode?
Z: it should be good,
M: There are two widely used multi-threaded versions. Will you write them?
Z: I will write it, but I know that you have to ask me the basics of multithreading, so I want to prepare it back.
M: See you tomorrow