①,super
super(len);
调用父类的构造方法中的初始化变量
super.getPerimeter()
父类与子类方法相同
认为子类重写父类,调用子类方法,隐藏父类方法,如果要调用父类方法,必须使用super关键字,super.getPerimeter()
②,实例化子类
1,初始化父类的类变量
2,初始化子类的类变量
3,调用父类的构造方法
4,调用子类的构造方法,
③,静态 static
1,静态方法只能调用静态方法
2,只能访问静态数据
3,不能使用 this,super
4,在任何方法调用之前,执行静态块
- static{
- system.out.print("这是首先执行的静态块");
- }
复制代码 ④ final修饰符
应用于方法,方法不能被重写,对象已声明为final,则引用不能更改,值可以更改
- public class Box{
- int height;
- Box(int h){
- height = h;
- }
- public static void main(String [] args){
- final Box boxobj = new Box(25);
- boxObj.height = 32;
- boxObj = new Box(32);//错误,对象引用不能修改
- }
- }
复制代码
⑤ 接口的实现和使用- //有方法的接口
- public interface firstInterface
- {
- public void outPut(int param);
- }
- //定义程序使用常量的接口
- public interface MyConstants
- {
- public static final double price = 1450.00;
- public static final int counter = 5;
- }
复制代码 1,接口中的所有方法必须是public 类型或默认类型。
2,方法仅仅是声明或定义,而不是要求去实现
3,接口可以通过使用关键字extends 继承其他接口4,当一个类实现一个接口时,它必须实现接口中定义的所有方法,否则该类必须声明抽象类。
⑥ lastIndexOf(s,20);- package first;
- public class StringMethods {
- public StringMethods() {
- // TODO Auto-generated constructor stub
- }
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- String s = "Java is a "+ "platform independent langtuaget";
- String s1 = "Hello world";
- String s2 = "Hello";
- String s3 = "HELLO";
-
- System.out.println(s);
- System.out.println("index of t = " + s.indexOf('t'));
- System.out.println("last index. of t = " + s.lastIndexOf('t'));
- System.out.println("index of(t,10) = " + s.indexOf('t',10));
- System.out.println("last index of(t,60) = "+s.lastIndexOf('t',15));
- }
-
- }
复制代码
lastIndexOf('t',15)); 从15这个位置,向前寻找,运行结果
- <p style="font-size: 11px; line-height: normal; font-family: Monaco;">Java is a platform independent langtuaget</p>
- <p style="font-size: 11px; line-height: normal; font-family: Monaco;">index of t = 13</p>
- <p style="font-size: 11px; line-height: normal; font-family: Monaco;">last index. of t = 40</p>
- <p style="font-size: 11px; line-height: normal; font-family: Monaco;">index of(t,10) = 13</p>
- <p style="font-size: 11px; line-height: normal; font-family: Monaco;">last index of(t,60) = 13</p>
复制代码 |