第二站: 广州亚美
笔试题
- 成员变量、类变量、实例变量和局部变量的区别?
Integer a= 300;
Integer b= new Integer(300);
Integer c= 300;
System.out.println(a==b);
System.out.println(a==c);
请问以上代码块会输出什么内容?
输出结果: false false
有意思的是,当300改变成1之后,结果就完全不一样
Integer a= 1;
Integer b= new Integer(1);
Integer c= 1;
System.out.println(a==b);
System.out.println(a==c);
输出结果:true true
两者的不同是因为Integer 类型内部有一个缓冲池,当Integer 的数值在-128~127 范围内, Integer 就会自动拆箱成int类型,int 类型的==是值比较,Integer 是引用比较。(大概是这个意思,可能不准确)
String a = new String("hello");
String b = new String("hello");
String c = "hello"
String d = "hello"
请问以上代码块新建了几个对象?
答案: 2个。
当有重复的String 类型(如c和d),会从字符串常量池直接引用地址,但是new 会强制新建一个对象, 也就是a和b会新建对象,c和d会直接引用a和b的内存地址,只会生成两个对象。
{
static int a=1;
public static void main(String args[]){
int a = 2;
System.out.println(a);
}
}
以上代码会输出什么结果
会输出2,局部变量会覆盖成员变量
- 抽象类和接口有什么区别。
抽象类 | 接口 |
---|---|
方法都是public abstract修饰,1.8以后可以static 和 default修饰 | 方法都是可以不是abstract修饰 |
成员变量一定是public static final修饰了,一定要赋予初值 | 可以不是abstract修饰的 |
使用implement实现 | 使用extends继承 |
-
ArrayList和LinkedList的区别
-
MySQL多对多关联怎么建立?
使用一张中间表,存储多张表的主键 -
设计使用单例模式创建对象
public instance Singleton(){
instance result;
private Singleton(){}
public instance Create(){ //饿汉式
result = new instance();
return result;
}
}
public instance Singleton(){
private static instance result = new instance() ;
private Singleton(){}
public instance Create(){
return result;
}
}
- 手写SQL:
查询一个表中所有学生数量
查询一个表中所有重复的学生名字
查询一个表中最后一名入学的学生信息
面试题
- 基本数据类型有哪些?
- Collection中线程安全的有哪些?原理是什么?
- 怎么查找表中第一个数据?第二个呢?
- input输入框怎么让它不能输入?