31,String s=new String(“xyz”); Several string objects are created ?

answer : Two objects , One is static storage "xyz", One is to use new Creating objects on the heap .


32, Is the interface inheritable (extends) Interface ? Is abstract class realizable (implements) Interface ? Can abstract classes inherit concrete classes (concrete class)?

answer : Interfaces can inherit interfaces . Abstract classes can be implemented (implements) Interface , Abstract classes inherit concrete classes , But the premise is that the concrete class must have an explicit constructor .


33, One “.java” Can multiple classes be included in the source file ( Is not an inner class )? What are the restrictions ?

answer : sure , However, there can be at most one public class in a source file (public class) The class name must be exactly the same as the public file name .


34,Anonymous Inner Class( Anonymous Inner Class ) Can I inherit other classes ? Can the interface be implemented ?

answer : You can inherit other classes or implement other interfaces , stay Swing This method is often used in programming to achieve event monitoring and callback .


35, An inner class can refer to its containing class ( Outer class ) Is it a member of ? Are there any restrictions ?

answer : An inner class object can access the members of the outer class object that created it , Including private members .


36,Java Medium final What are the uses of keywords ?


answer :(1) Modifying class : Indicates that the class cannot be inherited ;(2) Modification method : The representation method cannot be overridden ;(3) Modifying variables : Indicates that the variable can only be assigned once, and the value cannot be modified ( constant ).


37, Point out the running results of the following program :

1 class A{ 2 3 static{ 4 System.out.print("1"); 5 } 6 7 public A(){ 8
System.out.print("2"); 9 } 10 } 11 12 class B extends A{ 13 14 static{ 15
System.out.print("a"); 16 } 17 18 public B(){ 19 System.out.print("b"); 20 } 21
} 22 // He asked hovertree.com 23 public class Hello{ 24 25 public static void
main(String[] args){ 26 A ab = new B(); 27 ab = new B(); 28 } 29 30 }

answer : results of enforcement :1a2b2b. When an object is created, the order in which the constructor is called is : Initialize static members first , Then call the parent class constructor. , Reinitialize non static members , Finally, call the self constructor .



38, Conversion between data types :

1) How to convert a string to a basic data type ?

2) How to convert a basic data type to a string ?

answer :

1) Call the method in the wrapper class corresponding to the basic data type parseXXX(String) or valueOf(String) You can return the corresponding basic type ;

2) One way is to combine the basic data type with an empty string (””) connect (+) The corresponding string can be obtained ; Another way is to call String Class valueOf(…) Method returns the corresponding string


39, How to realize the inversion and replacement of string ?

answer : There are many ways , You can write it yourself or use it String or StringBuffer /
StringBuilder Methods in . There is a very common interview question is using recursion to achieve string inversion , The code is shown below :
public static String reverse(String originStr) { if(originStr == null ||
originStr.length() <= 1) return originStr; return
reverse(originStr.substring(1)) + originStr.charAt(0); } // He asked hovertree.com
40, How will GB2312 The encoded string is converted to ISO-8859-1 Encoded string ?

answer : The code is shown below :

String s1 = " Hello ";

String s2 = newString(s1.getBytes("GB2312"), "ISO-8859-1");


©2019-2020 Toolsou All rights reserved,
JavaScript note ( five )---- Branch statement Linux【shell】 shell programming Account password registration login forgotten password test case ( Very detailed )abaqus Value of mass scaling factor _ABAQUS Mass scaling for vue in input Box can only enter numbers RISC-V_GD32VF103-TIMER0 timer interrupt Java Student information management system console version 【 Hyper detail 】Java Realization of student information management system pandas Multiply two columns in html+css curriculum vitae / Web interface