Java基础阶段总结

1、接口:

接口是特殊的抽象类

 接口的定义格式:abstract通常不写

public abstract interface 接口名{}
2、内部类:

(1)匿名内部类:匿名子类的类名

(2)成员内部类:跟方法同级别的类,定义在一个类里面

           访问权限可以是四种访问权限的任意一种

  构造对象方式:

  a)static:外部类.内部类  对象名 = 外部类对象.new 内部类()

  b)Static:外部类.内部类  对象名 = new 外部类.内部类()

(3)方法内部类;直接在方法内部定义声明的类

      注意:一定不能有访问权限

注意:同一个文件的多个并列类,不是内部类结构

条件:只能有一个为public或者都是默认不写;如果有public的类,则这个类的类名必须和文件名一样

3、String


package com.test.exercise2;

public class StringTest {
	public static void main(String[] args) {
		String str = "ok,yes";
		char[] chars = { 'a', 'b', 'c' };
		new StringTest().change(str, chars);
		System.out.println(str);
		System.out.println(chars[0]);
	}

	public void change(String str, char[] chars) {
		str = new String();//创建一个新的空间
		str = "change";//新的空间里的值改成change
		chars[0] = 's';
	}
}

结果 


原因:


4、switch

switch(只能是String或者int),jdk1.7以后才能使用String

package com.test.exercise2;

public class SwitchTest {
	public static void main(String[] args) {
		String str = "aa";
		switch (str) {
		case "aa":
			System.out.println("我是”aa“");
			break;
		case "bb":
			System.out.println("我是“bb”");
			break;
		}
	}
}


package com.test.exercise2;

public class SwitchTest {
	public static void main(String[] args) {
		int value1 = 1;
		switch (value1) {
		case 1:
			System.out.println("我是“1”");
			break;
		case 2:
			System.out.println("我是“2”");
			break;
		}
	}
}

package com.test.exercise2;

public class SwitchTest {
	public static void main(String[] args) {
		short value1 = 1;
		switch (value1) {// 自动转型为int
		case 1:
			System.out.println("我是short“1”");
			break;
		case 2:
			System.out.println("我是short“2”");
			break;
		}
	}
}


package com.test.exercise2;

public class SwitchTest {
	public static void main(String[] args) {
		byte value1 = 1;
		switch (value1) {// 自动转型为int
		case 1:
			System.out.println("我是byte“1”");
			break;
		case 2:
			System.out.println("我是byte“2”");
			break;
		}
	}
}

5、int、byte、short

byte value = 1;
value=value+1;//会报错,byte类型+int类型结果是int类型

short value = 1;
value = value + 1;// 会报错,short类型+int类型结果是int类型
但是:

short value = 1;
value += 1;// 不会报错

byte value = 1;
value += 1;// 不会报错

6、接口继承接口

package com.test.exercise2;

public interface InterfaceTest {

}
package com.test.exercise2;

public interface InterfaceTest3 {

}
package com.test.exercise2;

public interface InterfaceTest2 extends InterfaceTest, InterfaceTest3 {// 没有错!!!

}





  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值