public String getId(String id){this .id=id;}
时间: 2024-04-30 08:18:15 浏览: 18
这段代码有语法错误。应该修改为:
```
public void setId(String id){
this.id = id;
}
```
这是一个setter方法,用于给类中的id属性赋值。修正后的代码中,参数id将被赋值给类中的id属性。需要注意的是,setter方法的返回值通常为void,因为它不需要返回任何值。
相关问题
public class Result { public String id; public String content; public String note; public String source; public String date; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getContent() { return content; } public void setContent(String content) { this.content = content; } public String getNote() { return note; } public void setNote(String note) { this.note = note; } public String getSource() { return source; } public void setSource(String source) { this.source = source; } public String getDate() { return date; } public void setDate(String date) { this.date = date; } }
这是一个 Java 类,名为 Result。它有五个实例变量:id、content、note、source 和 date,分别表示结果的标识、内容、注释、来源和日期。它还有五个方法,分别为 getId、setId、getContent、setContent、getNote、setNote、getSource、setSource、getDate 和 setDate,用于获取和设置这些实例变量的值。这个类可能用于存储和管理一些数据结果。
public class Notice { private int id; private String title; private String name; private String content; private String createtime; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getContent() { return content; } public void setContent(String content) { this.content = content; } public String getCreatetime() { return createtime; } public void setCreatetime(String createtime) { this.createtime = createtime; } public Notice(int id, String title, String name, String content, String createtime) { super(); this.id = id; this.title = title; this.name = name; this.content = content; this.createtime = createtime; } public Notice() { super(); // TODO Auto-generated constructor stub } }
这是一个 Java 类,名为 Notice,它具有五个私有属性,分别是 id、title、name、content 和 createtime。它还具有五个公有方法,分别是 getId、setId、getTitle、setTitle、getName、setName、getContent、setContent、getCreatetime 和 setCreatetime。其中,set 方法用于设置私有属性的值,get 方法用于获取私有属性的值。此外,还有两个构造方法,一个是带参数的构造方法,一个是无参构造方法。这个类可能用于存储通知的信息。