1, the following code to determine the operation of the situation
Public classTestextends { Public Static voidMain (string[] args) {Father obj=NewSon (); System.out.println (Obj.getele ()); }}classfather{ Public intGetele () {return1; }}classSonextendsfather{ Public floatGetele () {return2f; }}
Answer: compilation error. The reason is that a function cannot be distinguished by a return value, although the parent class has a different return value than the function in the subclass, but they have the same function name, so the compiler cannot distinguish it.
2, abstract method permission ID can only be modified by public or protected "NOTE: You can not do permission decoration-default".
3, the method in the interface can only be modified by public,abstract.
4. What are the internal classes and what are their characteristics?
The inner class is divided into four types: static inner class, member inner class, local inner class, and anonymous inner class.
① static inner classes are statically decorated, can be instantiated without relying on external instances, cannot have the same name as external classes, and cannot access non-static members of external classes.
② member inner classes are free to reference external member variables and methods (including private)
③ local inner classes cannot be modified by permissions modifiers such as public and static
④ Anonymous inner classes cannot use class, extends, implements, no constructors, must inherit classes, or implement interfaces, thus creating only one anonymous inner class instance. In addition, local inner class constraints also apply to anonymous inner classes.
5, how to get the class name of the parent class?
Answer: Use GetClass (). Getsuperclass (). GetName ().
Note : Why you cannot use Super.getclass (). GetName (), as explained below:
The GetClass () method is defined in the object class as final and native, which cannot be overridden by subclasses. So This.getclass () and Super.getclass () all call the object's GetClass (), and the interpretation of object's GetClass is a running class that returns object.
6, why should have super keyword?
In the example of a subclass that integrates the parent class, if the subclass overrides the method of the parent class, it must be called with super if you want to invoke the original method of the parent class.
7. Examples of super error use:
class father{ public Father () { System.out.println ("Dad in this");} } class extends father{ public Son () { System.out.println ("son here ~"); Super (); }}
Explanation: A compilation error will occur and super () must be the first statement in the subclass constructor.
8.
Java face question 002