基本数据类和包装类
int Integr
char Character
基本数据类 包装类 String类间的转换
前两个间 自动装箱 拆箱
Integer i = 10;
基本数据类和包装类 ------>String: valueof(xxx)
反过来 : ParseXxx(String s)
多态性
向上转型: 多态
向下转型:instanceof 关键字
封装性 继承性 多态性
面向对象 下
static 关键字
随着类加载而加载:早于对象的创建
static修饰 属性方法 代码块 内部类
单例设计模式
在整个软件中对某个类只存在一个对象实例,并且只提供一个取得对象实例的方法
要就熟练写出
饿汉式
/**
* Created on 2022/1/24.
*
* @author Jiaxiang Li
*/
public class Singleton {
}
//提供私有化构造器
private Singleton(){
}
//内部提供一个当前类的实例 此实例也必须静态化
private static Singleton Single = new Singleton();
//提供该实例的get方法
public static Singleton getInstance()(){
return Singleton;
}
懒汉式
/**
* Created on 2022/1/24.
*
* @author Jiaxiang Li
*/
public class Singleton {
}
//提供私有化构造器
private Singleton() {
}
//内部提供一个当前类的实例 此实例也必须静态化
private static Singleton Single;
//提供该实例的get方法
public static Singleton getInstance(){
if(Single == null){
Single = new Singleton();
}
return Single;
}
拿起来就能写
main()方法
代码块
final 关键字
修饰类 类不能被继承
修饰方法 方法不能被重写
修饰变量 变量变为常量
基本上修饰属性 变成常量
抽象类和抽象方法
abstract练习
/**
* Created on 2022/1/24.
*
* @author Jiaxiang Li
*/
public abstract class prac {
private String name;
private int id;
private int salary;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public int getSalary() {
return salary;
}
public void setSalary(int salary) {
this.salary = salary;
}
public prac(String name, int id, int salary) {
this.name = name;
this.id = id;
this.salary = salary;
}
public void work(){
}
}
模板方法设计模式
接口
接口中不能定义构造器 意味着接口不可以实例化
接口的应用
代理模式
import com.sun.corba.se.spi.orbutil.threadpool.Work;
/**
* Created on 2022/1/25.
*
* @author Jiaxiang Li
*/
public class Net {
public static void main(String[] args) {
Sever s2 = new Sever();
dailiSever dali1 = new dailiSever();
dali1.work(s2);
dali1.connect();
}
}
interface Network{
public void connect();
}
class Sever implements Network{
@Override
public void connect() {
System.out.println("真实服务器连接到网络");
}
}
class dailiSever implements Network{
private Network work;
public void check(){
System.out.println("准备操作");
}
public void work(Network work){
this.work = work;
}
@Override
public void connect() {
check();
work.connect();
}
}
内部类
如何实例化成员内部类对象
调用方法