日期:2014-05-20 浏览次数:20900 次
public class Return()
{
public int way()
{
return 1;
}
public static void main()
{
Return a = new Return();
a.way(); //引用这个方法时,返回一个1,但没有储存起来,返回值就被抛弃了。
int b = a.way();//引用这个方法时,返回的1储存起来,放到同一类型的变量b中.
}
}
------解决方案--------------------
举例子:
古月金帛三寿,想知道上海的某件事情,他会问溫家宝,溫家宝会问俞正声,俞正声问手下人,手下人把结果告诉俞正声,俞正声把结果告诉溫家宝,溫家宝把结果告诉古月金帛三寿。
void hu() {
System.out.println(wen());
}
String wen() {
return yu();
}
String yu() {
return shouxiaren();
}
String shouxiaren() {
return "hello";
}
------解决方案--------------------
public class Test {
public boolean test(int x){
if(x>0){
return true;
}else{
return false;
}
}
public static void main(String[] args) {
int x=1;
int y=0;
Test a = new Test();
System.out.println(a.test(x));
System.out.println(a.test(y));
}
}
------解决方案--------------------
int a;
private int val(){
return 5;
}
a=val();