Interview questions:
- Construct code blocks, construct methods, and prioritize static code?
- Static code blocks > Constructing code blocks > Construction Methods
Interview question: What is the difference between overload and override?
Overload: Method Overloading
Method names, parameters differ, and return values are not related
Different parameters:
1) different number of parameters
2) different parameter types
Override: Method Override (subclass defines a method declaration that is the same as a parent class)
Continue to use in the
2 about the difference between this and super?
This: Represents the object of the current class
Super: Represents the parent class spatial identity, which is understood as an object representing the parent class
应用场景: this: super: 成员变量 this.成员变量 super.成员变量 成员方法 this.成员方法() super.成员方法(); 构造方法 this()/this("..") 面试题:
- Local internal classes Access local variables, then problems occur? (Jdk7 previously included jdk7, this problematic)
- Error, need to add final decoration to local variables ...
- Why does this local variable have to be final decorated?
The local variable should also be used in the inner class, change the variable to a fixed value, always exist in memory, and invoke the members of the inner class through the main method.
Anonymous internal class interview questions:
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 inter3{
void Show ();//public abstract
}
Class outer7{
The code is padded
public static Inter3 method () {
//返回的是接口:当前并不提供接口的子实现类,所以只能用匿名内部类return new Inter3() { public void show() { System.out.println("helloworld"); }};
}
}
Test class
public class Test {
public static void Main (string[] args) {
Outer7.method().show();
}
}
Java Basic (four) face question