您的当前位置:首页正文

黑马程序员——Java语言--面向对象(二)

2024-11-28 来源:个人技术集锦
———–、、java学习型技术博客、期待与您交流!————

继承(上)

好处:

上个Demo和图欣赏一下:

class Person 
{
	String name;
	int age;
}

class Student extends/*继承*/ Person
{
	void study()
	{
		System.out.println(name+"..Student Study.."+age);
	}
}

class Worker extends/*继承*/ Person
{
	void work()
	{
		System.out.println(name+"..Worker Work.."+age);
	}
}

public class ExtendsDemo
{
	public static void main(String[] args)
	{
		Student s = new Student();
		s.name = "xiaoming";
		s.age = 20;
		s.study();
		Worker w = new Worker();
		w.name = "aaaa";
		w.age = 31;
		w.work();
	}
}

显示全文