[Java]
/*
* Start the program header annotation.
* Copyright and version Declaration of the program
* Copyright (c) 2011, a student from the computer College of Yantai University
* All rights reserved.
* File name: interface exercise
* Author: Xue Guangchen
* Completion date: January 1, October 18, 2012
* Version No.: x1.0
* Description of tasks and Solutions
* Input description:
* Problem description: (1) encapsulate ComputerWeight, which has three functions: double computrWeight, void printName, and double printPrice.
(2) encapsulate ComputerCompany, which has two functions: String computerName and void printFunction.
(3) encapsulate a class of object FlashMemory to implement the above two interfaces.
(4) Test the above object with a program execution entry.
* Program output:
* End the comment in the program Header
*/
// ComputerWeight Interface
// (1) encapsulate ComputerWeight, which has three functions: double computrWeight, void printName, and double printPrice.
Package myinterfance;
Public interface ComputerWeight {
Public double computrWeight = 10;
Public void printName ();
Public void printPrice ();
}
// ComputerCompany Interface
// (2) encapsulate ComputerCompany, which has two functions: String computerName and void printFunction.
Package myinterfance;
Public interface ComputerCompany {
Public String computerName = "dell ";
Public void printFunction ();
}
// FlashMemory class
Package myinterfance;
Public class FlashMemory implements ComputerWeight, ComputerCompany {
Public void printName (){
System. out. println ("The computer name is" + computerName );
}
Public void printPrice (){
System. out. println ("The computer Price is 6000 yuan ");
}
Public void printFunction (){
System. out. println ("Achieve print function ");
}
}
// Test class MyTest
Package myinterfance;
Public class MyTest {
/**
* @ Param args
*/
Public static void main (String [] args ){
// TODO Auto-generated method stub
FlashMemory fm = new FlashMemory ();
Fm. printName ();
Fm. printPrice ();
Fm. printFunction ();
}
}
Running result: