20. Can interfaces inherit interfaces? Can an abstract class implement (implements) interfaces? Can an abstract class inherit a concrete class (concrete Class)? Is there a static main method in the abstract class?
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.
Note: As long as you understand the nature and role of interfaces and abstract classes, these questions are good answers, and you think, if you are the Java language Designer, will you provide such support, if not provided, what is the reason? If you have no reason not to provide, then the answer is yes.
Just remember that the only difference between an abstract class and a normal class is that you cannot create an instance object and allow an abstract method.
21, when writing the Clone () method, usually have a line of code, what is it?
Clone has a default behavior,
Super.clone ();
22. What are the aspects of object-oriented features
Encapsulation : In an object-oriented programming language, objects are the most basic unit of encapsulation, and object-oriented encapsulation is the encapsulation of code that describes the properties and behavior of an object in a "module"
Abstraction : Abstraction is the identification of similarities and commonalities of things, and then the attribution of these things to a class
inheritance : In defining and implementing a class, it can be done on the basis of an existing class, the content defined by the already existing class as its own content, and inheritance is the mechanism by which subclasses automatically share the parent data and methods, which is a relationship between classes, Improved reusability and scalability of the software.
polymorphic: Polymorphism refers to the specific type of reference variable defined in the program and the method call issued through the reference variable is not deterministic during programming, but is determined during the program's run, that is, the instance object of the class to which a reference variable is inverted. The method call that the reference variable emits is exactly the method that is implemented in the class that must be determined by the time the program is run.
23. What is the mechanism for polymorphism in Java?
A reference variable that is defined by a parent class or interface can point to a subclass or an instance object of a concrete implementation class
24. What is the difference between abstract class and interface (interface)?
contains abstract modifier class is an abstract class, abstract class cannot create an instance object. The class containing the abstract method must be defined as abstract class , abstract Methods in class classes do not have to be abstract. Abstract class definitions must be implemented in specific (concrete ) subclasses, so there can be no abstract constructor method or abstract static method. If the subclass does not implement all abstract methods in the abstract parent class, then the subclass must also be defined as abstract type.
interface (interface ) can be said to be a special case of abstract classes, All methods in an interface must be abstract. The method definition in the interface defaults to public abstract type, the member variable type in the interface defaults to .
below compare the syntax differences between the two:
1. Abstract classes can have construction methods, and interfaces cannot have constructors.
2. An abstract class can have normal member variables, and there are no ordinary member variables in the interface
3. Abstract classes can contain non-abstract ordinary methods, and all methods in an interface must be abstract and cannot have non-abstract ordinary methods.
4. The access type of an abstract method in an abstract class can be public,protected and (the default type, although
eclipse does not give an error, but it should not), but the abstract method in the interface can only be of the public type, and the default is Span style= "color: #ff0000;" >public abstract type.
5. Abstract classes can contain static methods, interfaces cannot contain static methods
public static final type , and the default is public static final type.
7. A class can implement multiple interfaces, but can inherit only one abstract class.
25. What is an internal class? Can an inner class reference a member of its containing class? Are there any restrictions?
An inner class is a class that is defined inside a class, and a static member cannot be defined in an inner class. It's perfectly possible. If it's not a static inner class, there's no limit!
26. Is string the most basic data type?
The basic data types are byte, int, char, long, float, double, Boolean, and short.
The Java.lang.String class is of the final type, so you cannot inherit the class or modify the class. In order to improve efficiency and save space, we should use the StringBuffer class
27. Can I inherit the String class?
The string class is the final class and cannot be inherited.
28. The difference between string and StringBuffer
The JAVA platform offers two classes:String and StringBuffer,
They can store and manipulate strings, which are character data that contains multiple characters. This String class provides a string of values that cannot be changed. The string provided by this StringBuffer class is modified.
You can use StringBufferwhen you know that character data is going to change. Typically, you can use Stringbuffers to dynamically construct character data. In addition,string implements the equals method,new String ("ABC"). The result of equals (NewString ("abc") is true, and StringBuffer does not implement the equals method, so thenew StringBuffer ("abc"). Equals (Newstringbuffer ("abc") The result is false.
29. Does the array have the length () method? Does string have the length () method?
The array does not have the length () method, which has the length property. String has the length () method.
30, final, finally, finalize the difference.
final is used to declare properties, methods, and classes, respectively, that the property is immutable, that the method is not overridden, and that the class is not inheritable.
Internal classes to access local variables, local variables must be defined as final types, for example, a piece of code ...
finally is part of the exception-handling statement structure, which indicates that it is always executed.
Finalize is a method of the object class that, when executed by the garbage collector, calls this method of the reclaimed object, and can override this method to provide garbage collection of other resource recycles, such as closing the file. The JVM does not guarantee that this method is always called
Java Face Question Basics section (iii)