1、作用域public,private,protected,以及不写时的区别
答:区别如下:
作用域 当前类 同一package 子孙类 其他package
public √ √ √ √
protected √ √ √ ×
friendly √ √ × ×
private √ × × ×
不写时默认为friendly
2、arraylist和vector的区别,hashmap和hashtable的区别
答:就arraylist与vector主要从二方面来说.
一.同步性:vector是线程安全的,也就是说是同步的,而arraylist是线程序不安全的,不是同步的
二.数据增长:当需要增长时,vector默认增长为原来一培,而arraylist却是原来的一半
就hashmap与hashtable主要从三方面来说。
一.历史原因:hashtable是基于陈旧的dictionary类的,hashmap是java 1.2引进的map接口的一个实现
二.同步性:hashtable是线程安全的,也就是说是同步的,而hashmap是线程序不安全的,不是同步的
三.值:只有hashmap可以让你将空值作为一个表的条目的key或value
3、char型变量中能不能存贮一个中文汉字?为什么?
答:是能够定义成为一个中文的,因为java中以unicode编码,一个char占16个字节,所以放一个中文是没问题的
4、多线程有几种实现方法,都是什么?同步有几种实现方法,都是什么?
答:多线程有两种实现方法,分别是继承thread类与实现runnable接口
同步的实现方面有两种,分别是synchronized,wait与notify
5、继承时候类的执行顺序问题,一般都是选择题,问你将会打印出什么?
答:父类:
package test;
public class fatherclass
{
public fatherclass()
{
system.out.println("fatherclass create");
}
}
子类:
package test;
import test.fatherclass;
public class childclass extends fatherclass
{
public childclass()
{
system.out.println("childclass create");
}
public static void main(string[] args)
{
fatherclass fc = new fatherclass();
childclass cc = new childclass();
}
}
输出结果:
c:\>java test.childclass
fatherclass create
fatherclass create
childclass create
