java中的方法(method)到底怎么用?给个例子
来源:互联网 发布:晨曦软件支持什么系统 编辑:程序博客网 时间:2024/06/05 23:52
7.方法(method)
我们先举一个被调函数的例子,
int add(int x, int y){
return x+y;
}
以下为一个主调函数的例子,
for example:
int result = add(5,3);
大家可以看出来和c语言是一样的。
7.1 Variable Scope(变量范围)
1)Class(类) scope
Available to all methods in the class(类中所有的方法都可以用)
2)Block(块) scope
Available only with the block it is declared to,(只在他声明的块中有效) orwithin nested blocks(嵌套的块儿中)
3)Method(方法) scope
Available to a method which the variable is declaredwithin,(只在他声明的方法中有效)
以下例子中,i就是类变量,k 就是块儿变量,j就是方法变量,
public class VariableScope{
static int i = 10;
public static void main(String[] args){
int j = 20;
int r = cube(i);
。。。。。。由于篇幅限制,更多详情请见:http://www.mark-to-win.com/JavaBeginner/JavaBeginner1_web.html#Method
我们先举一个被调函数的例子,
int add(int x, int y){
return x+y;
}
以下为一个主调函数的例子,
for example:
int result = add(5,3);
大家可以看出来和c语言是一样的。
7.1 Variable Scope(变量范围)
1)Class(类) scope
Available to all methods in the class(类中所有的方法都可以用)
2)Block(块) scope
Available only with the block it is declared to,(只在他声明的块中有效) orwithin nested blocks(嵌套的块儿中)
3)Method(方法) scope
Available to a method which the variable is declaredwithin,(只在他声明的方法中有效)
以下例子中,i就是类变量,k 就是块儿变量,j就是方法变量,
public class VariableScope{
static int i = 10;
public static void main(String[] args){
int j = 20;
int r = cube(i);
。。。。。。由于篇幅限制,更多详情请见:http://www.mark-to-win.com/JavaBeginner/JavaBeginner1_web.html#Method
0 0
- java中的方法(method)到底怎么用?给个例子
- java中synchronized块是怎么用的给个例子
- java中 什么叫隐藏(Hide)? 最好给个例子
- java中死锁的概念是什么给个例子
- java语言解析json以后加入到listlist集合中,用代码应该怎么实现?可以举个例子吗
- Java中的utf-8到底怎么设定
- java 多线程实例,自己写的第一个例子,理解什么是多线程,怎么写多线程
- java的命令行参数到底怎么用,请给截图和实际的例子
- 用tween写个例子!
- 第二个例子(完整)
- java 方法(method)
- 深入浅出Hibernate中的第一个例子
- 写DIRECTDRAW中的第一个例子
- 【Inter汇编语言程序设计】中的第一个例子
- lsof在Linux中的10个例子
- android中的Context到底该怎么用
- android中的Context到底该怎么用
- java中的泛型之桥方法(bridge method)
- C 结构体内存对齐原则
- 收集的ORACLE函数大全
- linux中export用法
- vc++实现文件关联
- 关于js跳转的总结
- java中的方法(method)到底怎么用?给个例子
- linux随笔
- tar备份系统的方法
- 读《程序员应该知道的97件事》
- VC++实现多线程ddos
- 怎样快速在线将pdf文件转换成word
- Linux中的环境变量
- POJ 1185 炮兵阵地
- VC++实现数据包过滤(防火墙原理)