JAVA 程序求指点
解决时间 2021-05-15 06:59
- 提问者网友:骑士
- 2021-05-14 13:39
class person
{
String name;
String address;
String telphone;
String email;
void say(){
System.out.println ("person is saying");
}
}
class employee extends person{
String office;
double wage;
String hiredate;
}
class faculty extends employee{
String degree;
String level;
}
class text{
public void static main(String args[])
{
}
}
-----------------------------------------------------------------
我想给变量赋值并输出,请问怎么写
初学者不会
最佳答案
- 五星知识达人网友:猎心人
- 2021-05-14 14:34
根据你的代码来看,如果你的类都放在同一个java文件中,那么首先得把test类定义为public。
比如
employee ,在 Test中
employee em=new employee (); //注意啊,类名按命名规范第一个字母要大写
介于你没有getter和setter
赋值只能这样 em.name="张三";
调用方法 em.say(); //继承于super
全部回答
- 1楼网友:有你哪都是故乡
- 2021-05-14 17:24
前面加上:import java.io.BufferedReader;
import java.io.InputStreamReader;
public static void main(String [] arguments)throws Exception
{
System.out.println("请输入内容");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String inputStr = br.readLine(); //readLine();有按行读取的功能,你可以把上面的内容再重复一边,然后赋值到自己的变量里。
System.out.println(inputStr);
}
}
- 2楼网友:迷人又混蛋
- 2021-05-14 16:09
faculty f=new faculty();
f.say();
如果要输出:f.levent="值";
System.out.print(f.levent );
- 3楼网友:你可爱的野爹
- 2021-05-14 14:57
public class Person {
String name;
String address;
String telphone;
String email;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getTelphone() {
return telphone;
}
public void setTelphone(String telphone) {
this.telphone = telphone;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
void say(){
System.out.println ("person is saying");
}
}
class Employee extends Person{
String office;
double wage;
String hiredate;
public String getOffice() {
return office;
}
public void setOffice(String office) {
this.office = office;
}
public double getWage() {
return wage;
}
public void setWage(double wage) {
this.wage = wage;
}
public String getHiredate() {
return hiredate;
}
public void setHiredate(String hiredate) {
this.hiredate = hiredate;
}
}
class Faculty extends Employee{
String degree;
String level;
public String getDegree() {
return degree;
}
public void setDegree(String degree) {
this.degree = degree;
}
public String getLevel() {
return level;
}
public void setLevel(String level) {
this.level = level;
}
public static void main(String[] args) {
//实例化子类
Faculty f = new Faculty();
//给成员属性赋值
f.setAddress("中国");
f.setDegree("博士");
f.setEmail("123@163.com");
f.setHiredate("
在写出get set方法 以及输入的方法 或者直接给变量赋值 然后定义get方法 在main方法中用System.out.print();输出
我要举报
大家都在看
推荐资讯