abstractclassPerson {publicabstractvoideat();}publicclassDemo {publicstaticvoidmain(String[] args) {Person p =newPerson() {publicvoideat() {System.out.println("eat something");}};p.eat();}}
running result:eat somethingAs you can see, we directly implement the methods in the abstract class person in curly braces.This allows you to omit the writing of a classAlso, anonymous inner classes can be u
abstractclassPerson {public abstractvoideat();}publicclassDemo {publicstaticvoidmain(String[] args) {Person p =newPerson() {publicvoideat() {System.out.println("eat something");}};p.eat();}}
running result:eat somethingAs you can see, we directly implement the methods in the abstract class person in curly braces.This allows you to omit the writing of a classAlso, anonymous inner classes can be
abstractclassPerson {public abstractvoideat();}publicclassDemo {publicstaticvoidmain(String[] args) {Person p = newPerson() {publicvoideat() {System.out.println("eat something");}};p.eat();}}
running result:eat somethingAs you can see, we directly implement the methods in the abstract class person in curly braces.This allows you to omit the writing of a classAlso, anonymous inner classes can be
private and protected in front of class classes to indicate that only their external classes or their subclasses have access.2) The inner class in the method and scope is called a local inner class and is accessible only in its lexical scope. Constructors can be overloaded.
Dark Horse Programmer--java Foundation--Inner class------Java Training, Android training, iOS training,. NET training, look forward to communicating with you! -------Inner classIf class a requires direct access to the Members i
2018-05-07Inner classYou can define another class within one class.Why use internal classes?1) Enhanced encapsulation, hides the inner class inside the outer class, and does not allow other classes to access the inner class.2) The
Defined:You can place the definition of one class inside another class, which is the inner class. --Excerpt from Java programming ideasGeneral Implementation Method: Public classSimpleinnerclass {classContent {Private inti; Public intGetvlaue () {returni; } } classDescri
Such as:public class innerclassdemo{int x;Class a{static int a = 0;//is not legal to write this way.static final int b=0;//It's legal to write this.}}Answer: to put it simply, define a static domain or method that requires a static environment or a top-level environment, where the static environment specifically says that if you add static Class A In your
this troubled me, the result of the printing is 1 1, carefully go through the code, we should think about how the anonymous inner class is using the external class that method parameters.From the printed results, I guess I must have saved the position parameter in an instance of this inner
voidrun () {classinclass{ Public voidrun () {System.out.println ("Run Field i =" +i); }} inclass Inclass=NewInclass (); Inclass.run (); } }Three static inner classes/*** Static Inner class * 1. Static internal classes also have access to external class member variables * 2. External
To correctly understand the meaning of static when applied to an inner class, it is important to remember that the object of the inner class defaults to the handle of an object of the encapsulated class that created it. However, if we say that an
1. Access permission modifiersThe order from large to small is: public--protected--default--privateprivate--can only be used in the same class;default--does not need to write, default does not add. Can be used by classes in the same packageprotected--can be used by subclasses of different packagespublic--can be used by other classes of different packages2. modifier objects for various modifiers (which can be modified:
I learned some of the inner classes in Java today.An inner class is an inner class that places the definition of a class inside another class.Indicates that a reference to the
Constructing inner class objects by reflectionFirst, write a class containing the inner class under the Javalang package:
Package Javalang;
public class Outer {public
static class
1. Internal classes access member variables for external classes: Outer.this.sizepublic class Outer {private int size;public class Inner1 {private int size;public void display (int size) {size++;//reference D The formal parameter this.size++ of isplay function; Refers to the member variable outer.this.size++ in the inner clas
Such as:public class innerclassdemo{int x;Class a{static int a = 0;//It is illegal to write this way.static final int b=0;//It's legal to write this}}
Java class load order, the class is loaded first, the static variable is initialized, and then the object is created, and
class.The static code block executes only once, regardless of how many objects are created.Can be used to assign a value to a static variable for initialization of a class.1 Packagecom.oracle.demo04;2 3 Public classStatic {4 PrivateString name;5 Private intAge ;6 /*constructs a block of code to create an object to execute once*/7 //Building Code Blocks8 {9System.out.println ("This is the construction code block");Ten } One
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.