C # exercise on the eighth week of the Computer Task 2 Interface

Source: Internet
Author: User

[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:

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.