package collection;
import java.util.LinkedList;
/**
-
一
-
1、C
-
JVM判定两个类是否是同一个类,不仅根据类名去判断,还需要判断加载该类的类加载器是否是
-
同一个,相同的class文件被不同的类加载器加载得到的是不同的两个类
-
2、B
-
subString左闭右开
-
3、A
-
4、C
-
5、AB
-
重载:方法名相同 参数列表不同 返回值不能作为判断重载的条件
-
静态方法可以被重载,但是不能被重写
-
7、B
-
8、C
-
9、A 常量池中字符串常量只有一份
-
DEF equals比较的都是值
-
10、BC
-
二
-
super 1
-
三、
-
1、
-
直观上 抽象类除了定义抽象方法之外其他定义和普通类一样
-
接口当中定义的只能public static final常量和方法的声明
-
使用上 都不能使用new关键字创建对象
-
extends 单继承 implements 多实现
-
个人理解 举例说明什么需要用到抽象类 什么时候需要用到接口
-
jdk1.8后对于接口的改进 default static经常用于参数判断
-
2、String StringBuilder StringBuffer
-
String字符串本身是不可被修改 字符串拼接底层通过StringBuilder的append实现
-
StringBuilder和StringBuffer
-
3、a.当前类的加载器会从自己加载的类中查询是否有此类,如果有直接返回
-
b.如果没有,就去委派父类进行加载,父类也会使用相同的策略,直到委派到启动类加载器。
-
如果启动类加载器加载失败,就会向上尝试加载,继续失败则会使用App ClassLoader,
-
如果继续失败就会抛出ClassNotFoundException
-
安全性 避免类重复加载
-
loadClass以双亲委派的方式去加载
-
findClass找class文件 (重写)
-
defineClass从class字节码文件加载Class对象,然后class对象通过反射生成对象
-
4、 静态绑定就是编译时期能够确定的函数调用 invokeStatic
-
动态绑定就是运行时期才能够确定的函数调用 invokeVitual
-
四
-
1、
-
int myLen = Math.abs(len1-len2);
-
if(len1 > len2){
-
for(int i=0; i<myLen; i++){
-
head1 = head1.next;
-
}
-
}else{
-
for( int i=0; i<myLen; i++){
-
head2 = head2.next;
-
}
-
}
-
if(head1 != null && head2 != null && head1 == head2){
-
return true;
-
}else{
-
return false;
-
}
-
2、public static int partition(int[] array, int low, int high){
-
int tmp = array[low];
-
while(low < high){
-
while(low < high && array[high] >= tmp){
-
high--;
-
}
-
if(low >= high){
-
break;
-
}
-
if(array[high] < tmp){
-
array[low] = array[high];
-
}
-
while(low < high && array[low] <= tmp){
-
low++;
-
}
-
if(low >= high){
-
break;
-
}
-
if(array[low] > tmp){
-
array[high] = array[low];
-
}
-
}
-
array[low] = tmp;
-
}
*/
class Test1{
public void func1(){}
public void func1(int id){
}
}
class Test2 extends Test1{
public void func1(int id, String name){
}
}
class A{
public int i = method();
public static int j = method2();
public int k = 0;
public A(){
System.out.println(1);
}
public int method(){
System.out.println(2);
return 2;
}
public static int method2(){
System.out.println(3);
return 3;
}
}
class B extends A{
public int m = method3();
public static int n = method4();
public int t = 0;
public B(){
System.out.println(4);
}
public int method3(){
System.out.println(5);
return 5;
}
public static int method4(){
System.out.println(6);
return 6;
}
}
public class PreviousTest{
//约瑟夫环问题
public static void compute(int n, int key){
//n表示总人数 key表示关键数字
//定义一个标识数组
Boolean[] flags = new Boolean[n];
for(int i=0; i<n; i++){
flags[i] = true;
}
//当前存活的人数
int peopleLeft = n;
//定义一个计数器
int count = 0;
//定义一个位置点
int index = 0;
while(peopleLeft > 1){
//只要总人数>1都需要继续进行游戏
//只要当前位置点为true,count++
if(flags[index]){
//为true说明依然存活
count++;
if(count == key){
flags[index] = false;
count = 0; //计数器归0
peopleLeft--;
}
}
index++;
if(index == n){
index=0;
}
}
for(int j=0; j<n; j++){
if(flags[j]){
System.out.println("存活下来的人为: "+(j+1));
}
}
}
public static void compute1(int n, int key){
//使用LinkedList实现
LinkedList<Integer> list = new LinkedList<>();
for(int i=1; i<=n; i++){
list.addLast(i);
}
int index=0; //当前的位置点
while(list.size() > 1){
for(int i=1; i<=key; i++){
if(index == list.size()-1){
index = 0;
}else{
index++;
}
}
list.remove(index);
}
System.out.println("存活下来的人为: "+list.get(0));
}
public static void main(String[] args) {
compute(7, 3);
compute1(7, 3);
compute(10, 3);
compute1(10, 3);
compute(20, 3);
compute1(20, 3);
}
}
// public static void main(String[] args) {
// System.out.println(7);
// A a = new B();//7 3 6 2 1 5 4
// }