System.out.println("Inner "+address);//访问本内部类成员。 } } public void printInfo(){ Person person = new Person(); person.display(); //System.out.println(mail);//不可访问 //System.out.println(address);//不可访问 System.out.println(person.address);//可以访问内部类的私有成员 System.out.println(person.mail);//可以访问内部类的公有成员 } public static void main(String[] args) { StaticTest staticTest = new StaticTest(); staticTest.printInfo(); } }
Within a static nested class, non-static members of the outer class cannot be accessed, as
" + address);//Access this inner class member. }} public void Printinfo () {Person person = new person (); An external class accesses a non-static member of an inner class: instantiates an inner class to Person.display (); System.out.println (mail)///unreachable//SYSTEM.OUT.PRINTLN (address)//unreachable System.out.println (person.address); You can access the private member of the Inner class System.out.println (person.x);//The external class accesses the static members of the Inne
anonymous class will have a member variable that points to a reference to an external class2. If an anonymous class is to use one of the parameters in the method, the corresponding parameter of the method must be final, which seems to be mandatory for Java. and a member variable in an anonymous class points to the same storage area that the parameter object points to3. Anonymous class access to members of an external class is accessed through a stati
Objectivewhen writing a background program, often need to store the current server timestamp, the use of Timestamp is also very convenient, the client and server can be based on their own needs to do their own conversion
In PHP, get the current timestamp using the time () function, format the output through the date () function, Java is relatively complex, here a brief introduction
The Calendar,date,dateformat in the
of days you've been born to now Public Static voidMain (string[] args) {Calendar my=calendar.getinstance (); Calendar C=calendar.getinstance (); //Set Birth date 1995-05-10My.set (Calendar.year, 1995); My.set (Calendar.month,4); My.set (Calendar.date,10); //get the number of days in a time intDay =C.get (calendar.date); intMyday =My.get (calendar.date); System.out.println ( Day-myday);}Case 3: Find out how many days a day is away from a certain month Public Static voidMain (string[] args) {C
Java does not support multiple inheritance of classes, but you can use an inner class to inherit the implementation of more classes.
In the following example, the target class needs to inherit two abstract classes (A and B). The target class C itself inherits Class A and inherits another class B using an anonymous inn
Java Study Notes 20 --- adding internal classes to member Internal classes (1), Study Notes 20 ---
In the previous article, note 19 briefly introduced the internal class, local internal class, and anonymous internal class of the member, and added some content to the internal class of the member.
There are mainly the following six points:
1. The member's internal
Get started with java-8.9 Nested classes (using static internal classes)
In this section, we will discuss Nested classes.
1. Concept
When internal classes use static, they are nested classes.
package com.ray.ch07;public class Tes
inheritance is from top to bottom, Grandpa 1, Dad 1, Son 1, Grandpa 2, dad 2, son 2, not: grandpa 2, Son 1, is a mess like this. No, it's a joke. Therefore, class rules do not inherit the relationship, prevent chaos, and make the structure clear.Therefore, when we use a tree structure, we use classes.
There are still many such situations in our lives. For example, if Michael is a Chinese, Michael is also an American dual identity.Another example is
Introduction and summary of Anonymous Classes and lambda Expressions in java (Anonymous Classes and Lambda Expressions), lambdaexpressions
2017/6/30
Reprinted written Source: http://www.cnblogs.com/daren-lin/p/anonymous-classes-and-lambda-expressions-in-java.html
In this document, I checked the collection introduction
The following is my personal understanding, and I want to hear others' opinions.
In my opinion, objects, classes, and JavaProgramThere are some differences between classes and objects in the design.
Object-oriented:Class-in the concept, 'class' is a collection of similar things. In order to distinguish different clusters, such classes can be used as a template,
There are many other streams in the Java. Io package, mainly to improve performance and ease of use. C/C ++ can only provide byte streams. In Java, streams are divided into two types: byte streams and merge streams, which are represented by four abstract classes respectively (each type of stream includes two types of inputs and outputs, so there are four in total
Today and a friend talked about the invocation of the parent-private method, which was supposed to be easy to do with reflection, because it seemed to make no difference whether it was private or not, but it was not possible to invoke the private method of the call itself, but not the private method of invoking the parent class. The reason for this is probably because the Getdeclaredmethod method and the GetMethod method do not look for a private method of the parent class, so they have to write
obj.test (); at } - } - /* - F:\java_example>java Testouter - The out_i is*/View CodeFirst call this display () function to print out the out_i, it first in the display () function to find whether the variable, not to the inner class to find, and finally to outer class to find the variable2, the use of internal classesInternal classes make program code more compact and modular.When the program code in
There are many other streams in the java.io package, mainly to improve performance and ease of use. C + + can only provide byte streams. There are two kinds of streams in Java, one is the byte stream, the other is a stream of characters, which is represented by four abstract classes (each stream includes input and output, so altogether four): Inputstream,outputstream,reader,writer. Other streams of varying
Interfaces can inherit Interfaces. Abstract classes can implement (implements) interfaces, and abstract classes can inherit concrete Classes. There can be static main methods in an abstract class.Q: Does an abstract class inherit entity classes (concrete Class)A: An abstract class can inherit an entity class, but only
Basic theory:
-----------------------------------------------------
About Java Inner classes: an inner class is defined as a class that is defined within another class.
The reason for this exists is:
1. An object of an internal class can access the implementation of the object that created it, including private data. That is, an internal class instance is privileged for an instance of which class contains
The Java static internal class defines an inner class as a static class, which is essentially the same as the method of defining other classes as static classes. However, the details are still very different. Specifically, there are several places to draw attention to the program developers. (a) in general, if an inner class is not defined as a static inner
classes } }; Public voidFun () {//methods for defining external classes NewInner (). print ();//invoking a method by instantiating an object from an inner class }}; Public classinnerclassdemo04{ Public Static voidMain (String args[]) {Outer out=NewOuter ();//External Class Instantiation ObjectOuter.Inner in = out.NewInner ();//instantiating an inner class objectIn.print ();//methods fo
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.