为什么多个参数有返回值的方法return可以返回一个值?

package com.imooc.nonmotor;

public class NonMotor {

private String name;

private String color;

private int lunzi;

private int chair;

public NonMotor() {}

public void NonMotor(String name,String color) {

this.name=name;

this.color=color;

}

public  NonMotor(String name,String color,int lunzi, int chair) {

this.name=name;

this.color=color;

this.lunzi=lunzi;

this.chair=chair;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public String getColor() {

return color;

}


public void setColor(String color) {

this.color = color;

}

public int getLunzi() {

return lunzi;

}

public void setLunzi(int lunzi) {

this.lunzi = lunzi;

}

public int getChair() {

return chair;

}

public void setChair(int chair) {

this.chair = chair;

}

public String work(String name, String color,int lunzi, int chair) {

System.out.println("父类信息测试:这是一辆"+ color  + "色的"+name+"牌非机动车,有"+ lunzi+"个轮子,有"+chair +"个座椅") ;

return  name;//我不理解,为什么让返回一个。

}

}


package com.imooc.test;

import com.imooc.nonmotor.Bicycle;

import com.imooc.nonmotor.ElectricVehicle;

import com.imooc.nonmotor.NonMotor;

import com.imooc.nonmotor.Tricycle;

public class Test {

public static void main(String[] args) {

NonMotor one = new NonMotor();

one.work("天宇","红", 4, 1);

Bicycle two = new Bicycle();

two.biwork("捷安特", "黄", 1, 1);

ElectricVehicle three = new ElectricVehicle();

three.elwork("天宇","红", 4, 1, "飞鸽");

Tricycle four = new Tricycle();

four.triwork("天", "洪", 3, 1);

}

}

父类信息测试:这是一辆红色的天宇牌非机动车,有4个轮子,有1个座椅

自行车类信息测试:这是一辆黄色的捷安特牌自行车

电动车类信息测试:这是一辆使用飞鸽牌电池的非机动车

三轮车类信息测试:三轮车是一款有3个轮子的非机动车



整个代码运行最后正常。我只是非常不理解,为什么return name 这一个参数  它就能显示正常?



qq_踏雪_5
浏览 1200回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java