学习java 心得笔记-女黑客-必火安全学院

女黑客

 找回密码
 立即注册

QQ登录

只需一步,快速开始

学习java 心得笔记

[复制链接]
发表于 2017-9-16 00:40:55 | 显示全部楼层 |阅读模式
①,super
super(len);
调用父类的构造方法中的初始化变量

super.getPerimeter()
父类与子类方法相同
认为子类重写父类,调用子类方法,隐藏父类方法,如果要调用父类方法,必须使用super关键字,super.getPerimeter()

②,实例化子类
1,初始化父类的类变量
2,初始化子类的类变量
3,调用父类的构造方法
4,调用子类的构造方法,

③,静态 static
1,静态方法只能调用静态方法
2,只能访问静态数据
3,不能使用 this,super
4,在任何方法调用之前,执行静态块
  1. static{
  2.     system.out.print("这是首先执行的静态块");
  3. }
复制代码
④ final修饰符
应用于方法,方法不能被重写,对象已声明为final,则引用不能更改,值可以更改
  1. public class Box{
  2.     int height;
  3.     Box(int h){
  4.         height = h;
  5.     }
  6.     public static void main(String [] args){
  7.         final Box boxobj = new Box(25);
  8.         boxObj.height = 32;
  9.         boxObj = new Box(32);//错误,对象引用不能修改
  10.     }
  11. }
复制代码

⑤ 接口的实现和使用
  1. //有方法的接口
  2. public interface firstInterface
  3. {
  4.         public void outPut(int param);

  5. }
  6. //定义程序使用常量的接口
  7. public interface MyConstants
  8. {
  9.         public static final double price = 1450.00;
  10.         public static final int counter = 5;
  11. }
复制代码
1,接口中的所有方法必须是public 类型或默认类型。
2,方法仅仅是声明或定义,而不是要求去实现
3,接口可以通过使用关键字extends 继承其他接口4,当一个类实现一个接口时,它必须实现接口中定义的所有方法,否则该类必须声明抽象类。

⑥ lastIndexOf(s,20);
  1. package first;

  2. public class StringMethods {
  3.         public StringMethods() {
  4.                 // TODO Auto-generated constructor stub
  5.         }

  6.         public static void main(String[] args) {
  7.                 // TODO Auto-generated method stub
  8.                 String s = "Java is a "+ "platform independent langtuaget";
  9.                 String s1 = "Hello world";
  10.                 String s2 = "Hello";
  11.                 String s3 = "HELLO";
  12.                
  13.                 System.out.println(s);
  14.                 System.out.println("index of t = " + s.indexOf('t'));
  15.                 System.out.println("last index. of t = " + s.lastIndexOf('t'));
  16.                 System.out.println("index of(t,10) = " + s.indexOf('t',10));
  17.                 System.out.println("last index of(t,60) = "+s.lastIndexOf('t',15));
  18.         }
  19.         
  20. }
复制代码

lastIndexOf('t',15));
从15这个位置,向前寻找,运行结果

  1. <p style="font-size: 11px; line-height: normal; font-family: Monaco;">Java is a platform independent langtuaget</p>
  2. <p style="font-size: 11px; line-height: normal; font-family: Monaco;">index of t = 13</p>
  3. <p style="font-size: 11px; line-height: normal; font-family: Monaco;">last index. of t = 40</p>
  4. <p style="font-size: 11px; line-height: normal; font-family: Monaco;">index of(t,10) = 13</p>
  5. <p style="font-size: 11px; line-height: normal; font-family: Monaco;">last index of(t,60) = 13</p>
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|小黑屋|女黑客 |网站地图

© Copyright 2021 版权所有(一极教育科技有限公司)

津ICP备17008032号-3
快速回复 返回顶部 返回列表