comment.getBlog().getId();
获取发帖子的用户,这段代码怎么实现,我写后面的get报错,没法实现
写出这样的式子的话,需要用到三个类:
一个是Blog类,里面有成员变量id,和getId方法
一个是MyComment类,里面有成员变量Blog类,和getBlog类
最后是测试类:
/**
* @author liar
* @date 编写时间: 2022/4/18 19:22
*/
public class Comment {
public static void main(String[] args) {
//comment.getBlog().getId();
MyComment comment = new MyComment();
comment.getBlog().getId();
}
}
class MyComment{
private Blog blog;
public Blog getBlog() {
return blog;
}
}
class Blog{
private int id;
public int getId() {
return id;
}
}