Interview Question one:
/*
According to the requirements, the code
Interface Inter {void Show ();
Class Outer {//Padded code}
Class Outerdemo {
public static void Main (string[] args) {
Outer.method (). Show ();
}
}
Required to output "HelloWorld" on the console
*/
Interface Inter {void show ();//abstract method in interface, default format: public abstract}class Outer {//Complement code public static Inter method () {//Subclass Object-- Subclass Anonymous Object Inter i = new Inter () {//Return value type is a reference type interface type Interpublic void Show () {System.out.println ("HelloWorld");}}; Return i;/* the above code equivalent to the following: return new Inter () {public void Show () {System.out.println ("Hello word!");}}; */}}class Outerdemo {public static void main (string[] args) {Outer.method (). Show ();//Returns an object. X.show ();/*1:outer.method () can see that method () should be a static method in Outer. 2:outer.method (). Show () can see that the return value of method () is an object. Because show () should be called by the object and because there is a show () method in interface Inter, I think the return value type of the method () is an interface. */}}
Interview question two:
/*
interview:
Ask to fill in the blanks separately output 30,20,10.
Note:
1: Inner and outer classes do not have an inheritance relationship.
2: Qualifying This object with an external class name
outer.this
*/
Class Outer {
public int num = 10;
Class Inner {
public int num = 20;
public void Show () {
int num = 30;
SYSTEM.OUT.PRINTLN (fill in the code);
SYSTEM.OUT.PRINTLN (fill in the code);
SYSTEM.OUT.PRINTLN (fill in the code);
}
}
}
Class Innerclasstest {
public static void Main (string[] args) {
Fill in the code.
}
}
Class Outer {public int num = 10;class Inner {public int num = 20;public void show () {int num = 30; SYSTEM.OUT.PRINTLN (num); System.out.println (This.num); System.out.println (Outer.this.num);}}} Class Innerclasstest {public static void main (string[] args) {//external class name. Inner Class Name Object name = Outer Class object. Inner class object; Outer. Inner oi = new Outer (). New Inner (); Oi.show ();}}
An object-oriented anonymous inner class question in the first season of Java entry