Java 面试(一)基础知识 (3)

  如果一个Java对象的所属类或者其任意一个父类实现了接口 java.io.Serializable 或者它的子类 java.io.Externalizable,那么我们称这个对象是可序列化的。

  (https://www.geeksforgeeks.org/object-serialization-inheritance-java/)

  (https://www.geeksforgeeks.org/serialization-in-java/)

  18、静态属性和静态方法是否可以被继承?是否可以被重写?以及原因?

  都可以被继承;

  静态方法可以被重写,但重写的方法也必须是静态的;

  属性只存在隐藏一说,没有重写一说。

  19、静态内部类的设计意图

  非静态内部类在编译完成后会隐含地保存一个引用,该引用指向创建它的外部类。但是,静态内部类没有这样的引用,意味着静态内部类的对象创建不依赖外部类的对象创建,因此不能访问外部类任何的非静态成员。

  参考:

  One common use of a static member class is as a public helper class, useful only in conjunction with its outer class.

  One common use of a nonstatic member class is to define an Adapter that allows an instance of the outer class to be viewed as an instance of some unrelated class. 

  Use a non-static nested class (or inner class) if you require access to an enclosing instance\'s non-public fields and methods.

  Use a static nested class if you don\'t require this access.

  20、成员内部类、静态内部类、局部内部类和匿名内部类的理解,以及项目中的应用

  21、谈谈对Kotlin的理解

  Kotlin的设计目标:创建一种兼容Java的语言,它比Java更安全、更简洁。

  22、闭包和局部内部类的区别

  闭包在现在的很多流行的语言中都存在,例如 C++、C# 。闭包允许我们创建函数指针,并把它们作为参数传递。即函数式编程,Java 8提供了Lambda表达式,Lambda实现了函数式编程,可以用于替代广泛使用的匿名内部类实现回调功能,用于事件响应器。

  (https://www.oschina.net/translate/at-first-sight-with-closures-in-java?lang=chs&page=1#)

  23、String 转换成 Integer的方式及原理

  Integer.parseInt("10");

  String的本质是char数组(String.toCharArray()),我们可以根据ASCII表,将一个数字字符转换成一个数字。如字符‘0’~‘9’的ASCII值为48~57。

char[] chars={\'0\',\'1\'}; System.out.println(chars[0]); //0 int c=(int)chars[0]; System.out.println(c); //48

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zgjyzy.html