[英]Can you call a private constructor from another class?
So I am trying to write a method that writes a list of students put into a treemap, but my treemap is in my StudentViewcontroller. 因此,我正在尝试编写一种方法,该方法将放入树状图中的学生列表写入,但树状图位于StudentViewcontroller中。 Am I able to call it from my into my write student method. 我可以从我的write Student方法中调用它吗?
Here is my WriteStudent method so far:
Public void WriteStudent(PrintWriter pw) {
try{
for (Map.Entry<String, Student> s : studentMap.entrySet()){
}
}catch(FileNotFoundException e){
}
}
Here is my treemap for the studentviewcontroller: 这是我为studentviewcontroller的树图:
public class StudentViewController {
//A tree map to store the students
private TreeMap<String, Student> studentMap = new TreeMap<String, Student>();
If you had a private constructor then you couldn't invoke it directly from any other class. 如果您有私有构造函数,则无法直接从任何其他类调用它。 However, you don't have a private constructor. 但是,您没有私有的构造函数。 Your class has a field (with private access permissions) which is of type TreeMap<String,Student>
and named studentMap
. 您的班级有一个字段(具有私有访问权限),该字段的类型为TreeMap<String,Student>
,名称为studentMap
。 This is a private constructor. 这是一个私有构造函数。
private StudentViewController() {
super();
}
您不能从另一个类调用私有构造函数,私有构造函数,方法和变量只能由其所有者类调用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.