标签:style blog ar color os 使用 sp java strong
封装
实际上使用方法将类的数据隐藏起来,控制用户对类的修改和访问的权限。
封装是一种信息隐藏技术,在java中通过关键字private实现封装。
继承
使用已存在的类作为基础建立新类的技术,新类的定义可以增加新的数据或新的功能,也可以使用父类的功能,使得复用原来的代码非常容易,能够大大的缩短开发周期。
public class Animal {
private int age;
String sex="femaleanimal";
protected void sleep(){
System.out.println("i can sleep");
}
public Animal(){
System.out.println("this is super class(fulei)");
}
void eat()
{
System.out.println("i can eat");
}
void call()
{
System.out.println("--------------");
}
}
class Dog extends Animal{
public Dog() {
}
void call() {
// TODO Auto-generated method stub
System.out.println("--------wangwang------");
}
}
class Cat extends Animal{
void call()
{
System.out.println("-----miaomiao---------");
}
}
多态
多个字类继承共同的父类,定义的时候使用相同的父类指向不同的子类对象的引用
强制类型转换与instanceof关键字
Instance of 就是代表某个对象是某个类的实例的意思
标签:style blog ar color os 使用 sp java strong
原文地址:http://www.cnblogs.com/tianhao/p/4168276.html