/**
* 静态导入
*/
package cn.sxt.gao;
import cn.sxt.oo.*;//用别的包的类需要导入别的包,表示该包下所有类全部导入
import java.util.Date;
import static java.lang.Math.*;//导入静态属性Math类
public class Test {
public static void mian (String[] args){
User user = new User();//用别的包里面的类
//古老的方法 cn.sxt.oo.User user = new cn.sxt.oo.User();
Date data = new Date();//多个重名的类需要用咱们最古老的方法来标记类
System.out.println(Math.PI);
System.out.print(PI);
}
}
package cn.sxt.oo2;
/**
* 测试继承 java中只有单继承没有多继承,接口存在多继承
* @author Administrator
*可以使用Ctrl+T方便查看类的继承层次
*/
public class TestExtends {
public static void main(String[] args){
Student stu = new Student(null, 0, null);
stu.height = 176;
stu.name = "刘总分";
stu.rest();
Student stu2 = new Student("xixi",6,"挖掘机");
//instanceof二院运算符左边对象右边是类,当对象右面类或子类所创建对象时返回ture;否则返回flase
System.out.println(stu2 instanceof Student );
System.out.println(stu2 instanceof Person);
System.out.println(stu2 instanceof Object);
System.out.println(new Person() instanceof Student);
}
}
class Person{//默认继承object class Person extends object
String name;
int height;
public void rest(){
System.out.println("休息一会");
}
}
class Student extends Person{//子类继承父类(除了父类中的构造方法)
String major;
public void Student(){
System.out.println("学习俩小时");
}
public Student(String name,int height,String major){
this.name = name;
this.height = height;
this.major = major;
}
}
//instanceof二院运算符左边对象右边是类,当对象右面类或子类所创建对象时返回ture;否则返回flase
原文地址:https://www.cnblogs.com/dream2060/p/10525527.html