1,封装-保证数据安全-属性私有化
,2,多态-需要继承做基础,多种形态,重载
调用方法时,先找父类,没有会报错,有则会继续去子类中找,若有则执行子类方法,若无则执行父类方法
,3,设计模式 -单例模式(懒汉式,饿汉式)
一个类最多只允许创建一个对象
,4,构造函数私有
oracle – 神域
悲观性检测

==
equals

public class Pet {
public String name;
public void follow(){
	System.out.println("奔跑");
}
}
public class Eagle extends Pet{
	public void follow(){
		System.out.println("飞快跑");
	}
}
public class Cat extends  Pet{
	public void follow(){
		System.out.println("慢跑");
	}
}
public class Dog extends Pet{
	public void follow(){
		System.out.println("快跑");
	}
}
public class Hero {
public String name;
public Pet pet;
public Hero(String name) {
	this.name = name;
}
public Hero(String name, Pet pet) {
	super();
	this.name = name;
	this.pet = pet;
}
public void run(){
	System.out.println(this.name+"跑");
	pet.follow();
}
}
public class Test {
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Pet p = new Cat();
		Hero h = new Hero("蓝精灵",p);
		h.run();	
	}
}

蓝精灵跑
慢跑

5,包装类

byte - Byte
short - Short
int - Integer
long - Long
float - Float
double - Double
char - Character
boolean- Boolean

6,instanceof:关键字 判断对象是否是该类实例
7,类之间的关系:继承
关联(聚合,组合):一个类作为另一个类属性存在
依赖:一个类作为另一个类方法的参数
静态块:static{} 类加载时被调用执行
非静态块:创建对象时

Integer   Scanner
public class JingTai {
	{
		System.out.println("父类非静态块");
	}
	static{
		System.out.println("父类静态块");
	}
	public JingTai(){
		System.out.println("父类构造函数");
	}
}
public class ZiLei extends JingTai {
	{
		System.out.println("子类非静态块");
	}
	static{
		System.out.println("子类静态块");
	}
	public ZiLei(){
		System.out.println("子类构造函数");
	}
}
public class Test2 {
	public static void main(String[] args) {
		JingTai j = new ZiLei();
	}
}

父类静态块
子类静态块
父类非静态块
父类构造函数
子类非静态块
子类构造函数

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值