Java abstract 抽象类

package com.ssm.cts.test;

public abstract class Bike {
  private String name;
  
  public abstract void start();
}
package com.ssm.cts.test;

public class MotoBike extends Bike {

  @Override
  public void start() {
    System.out.println("启动");
  }

}
package com.ssm.cts.test;

public class ClassTest {
    // 测试
  public static void main(String[] args) {
    Bike bike = new MotoBike();
    bike.start();
  }

}

Java implements 类继承

使用 implements 关键字可以变相的使java具有多继承的特性,使用范围为类继承接口的情况,可以同时继承多个接口(接口跟接口之间采用逗号分隔)。

package com.ssm.cts.test;

public interface ICar {
  public void start();
  
  public void stop();
}
package com.ssm.cts.test;

public interface ICarFly {
  public void restart();
  
}
package com.ssm.cts.test;

public class BusCar implements ICar, ICarFly {

  @Override
  public void restart() {
    System.out.println("重启");
  }

  @Override
  public void start() {
    System.out.println("启动");
  }

  @Override
  public void stop() {
    System.out.println("停止");
  }

}
package com.ssm.cts.test;

public class ClassTest {
    // 测试
  public static void main(String[] args) {
    BusCar bus = new BusCar();
    bus.start();
    bus.stop();
    bus.restart();
  }

}
阅读全文

Java extends 类继承

package com.ssm.cts.test;

public class Car {
  public String code;
  private String name;

  public Car(String _name) {
    super();
    this.name = _name;
  }
  
  public void start() {
        System.out.println(name + "启动");
    }
  
  public void stop() {
        System.out.println(name + "停止");
    }
  
}
package com.ssm.cts.test;

public class MiniCar extends Car {

  public MiniCar(String _name) {
    super(_name);
  }

  // 子类可以用自己的方式实现父类的方法
  public void start() {
    // 子类拥有父类非private的属性,方法
        System.out.println(super.code + "启动");
    }
  
  // 子类可以拥有自己的属性和方法
  public void restart() {
    System.out.println("重启");
    super.stop();
    super.start();
    }
}
package com.ssm.cts.test;

public class ClassTest {
    // 测试
  public static void main(String[] args) {
    MiniCar car = new MiniCar("001", "别克");
    car.start();
    car.stop();
    car.restart();
  }

}

Java SimpleDateFormat 格式化日期

package com.ssm.cts.test;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;
import java.util.Stack;
import java.util.Vector;

public class ClassTest {
    // 测试
  public static void main(String[] args) {
    
    Date dNow = new Date( );
      SimpleDateFormat ft = new SimpleDateFormat ("yyyy-MM-dd hh:mm:ss");
      System.out.println("当前时间为: " + ft.format(dNow));
  }
}

Java String

package com.ssm.cts.test;

import java.util.Enumeration;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;
import java.util.Stack;
import java.util.Vector;

public class ClassTest {
    // 测试
  public static void main(String[] args) {
    
    String home = "chanpinxue.cn";
        int len = home.length();
        System.out.println("网址长度 : " + len);
        // 连接字符串
        System.out.println("idodo".concat(".xin"));
        System.out.println("idodo" + ".xin");
        System.out.println(String.format("%s%s", "idodo", ".xin"));
        // 替换
        System.out.println("jiangzhihao".replace("hao", "9001"));
  }
}