stem.java

来自「是一个关于JAVA的文件」· Java 代码 · 共 71 行

JAVA
71
字号

//  第六章 练习题10

//  原题:
//  Create a class called Root that contains an instance of each of the classes 
//  (that you also create) named Component1,Component2,Component3.Derive a class Stem from
//  Root that also contains an instance of each "component" All classes should have 
//  default constructors that print a message about that class.


class component1
{
	int a=1;
	public component1()
	{
		System.out.println("component1 constructed!");
	}
}

class component2
{
	int b=2;
	public component2()
	{
		System.out.println("component2 constructed!");
	}
}

class component3
{
	int c=3;
	public component3()
	{
		System.out.println("component3 constructed!");
	}
}



class root
{
	component1 com1=new component1();
	component2 com2=new component2();
	component3 com3=new component3();
	
	public root()
	{
		System.out.println("component1、2、3 are already components of class root!");
	}
}



public class stem extends root
{
		public stem()
	{
		System.out.println("component1、2、3 are also components of class stem!");
	}
}



class workout
{
   public static void main(String args[])
   {
   	stem st=new stem();
   	System.out.println("st.com1.a="+st.com1.a+"  st.com2.b="+st.com2.b+"  st.com3.c="+st.com3.c);
   }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?