chapter4My--Java教案.doc

4.1 类的定义和使用 1、最简单的类 class Mankind { } 2、类的数据 class Mankind { int sex; int salary; } 3、类的方法 class Mankind { void name () { System.out.println( “My name is abc” ); } void income ( int wage ) { System.out.println ( “My income this year is ” + wage ); } } 方法的组成部分: 方法名 方法的返回值 方法的参数 例如:编写一个功能模块,他能够将两个整数按照用户的意愿进行四则运算 第一步:定义出一个方法,他能够完成这样的功能 void Function( int x , int y , char c ) { long result = 0 ; if ( c == ‘+’ ) result = x + y; else if ( c == ‘-’ ) result = x - y; else if ( c == ‘*’ )

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档