我在使用以下代码时遇到问题...
/**
* This class holds all of the information pertaining to
* a person's name.
*/
public class Name {
private String first, middle, last, maiden, initials, prefix, suffix;
private char middleInitial, firstInitial, lastInitial;
private
/**
* Constructor for a Name given first, middle, and last names.
*/
public Name(String first, String middle, String last) {
this.first = first;
this.middle = middle;
this.last = last;
this.middleInitial = middle.charAt(0);
this.firstInitial = first.charAt(0);
this.lastInitial = last.charAt(0);
this.initials = String.valueOf(firstInitial + middleInitial
+ lastInitial);
this.maiden = null;
this.prefix = null;
this.suffix = null;
}
还有更多,但我的错误出现在我的主构造函数中。它给了我我在标题中输入的错误。如您所见,我的类和构造函数都是公共(public)的。这不应该引起任何问题,但似乎正在这样做。
最佳答案
在构造函数的注释之前有一个“孤立”private
修饰符:
private // Here!
/**
* Constructor for a Name given first, middle, and last names.
*/
public Name(String first, String middle, String last) {
只要将其删除,就可以了。
关于java - 修饰符组合非法 : public and private,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30944551/