展开全部
public class Test
{
public static void main(String[] args){
Computer computer = new Computer("IBM","2.4GHz",8000);
Student stu = new Student(computer);
System.out.println(stu.getComputerBrand());
System.out.println(stu.getComputerFrequency());
System.out.println(stu.getComputerPrice());
}
}
class Student
{
private Computer computer;
public Student(Computer c)
{
computer = c;
}
public String getComputerBrand()
{
return computer.getBrand();
}
public String getComputerFrequency()
{
return computer.getFrequency();
}
public double getComputerPrice()
{
return computer.getPrice();
}
}
class Computer
{
private String brand;
private String frequency;
private double price;
public Computer(String b,String f,double p)
{
brand = b;
frequency = f;
price = p;
}
public String getBrand()
{
return brand;
}
public String getFrequency()
{
return frequency;
}
public double getPrice()
{
return price;
}
}