问题是从实践中删除“ this”关键字。设置/获取方法[重复]

问题描述 投票:0回答:1

我正在尝试从编码中删除“ this”关键字,以更好地了解Java的工作原理。不幸的是,我遇到了“变量名称无法解析为变量”的问题。有人可以帮我了解我在做什么错。

我已经尝试过更改变量名,但前提是Java在尝试查找要执行的我要引用的“变量”时遇到问题,但是却不惜一切代价失败了。

我也附上了UML diagramSample Output以供参考。 *我还没有弄清楚如何返回带有空变量的第一个字符串,所以这不在代码中。

public class Assignment
{
  private String assignCourse,
                 assignSctn,
                 assignType;
  private int assignDue;
  
   public Assignment()
   {
     //null constructor
   }//END null constructor
   
   public Assignment(String course, String section, String type, int due)
   {
     assignCourse = course;
     assignSctn = section;
     assignType = type;
     assignDue = due;
   }//END full constructor
   
   //Set mutator methods for variables
   
   public final void setAssignCourse(String course)
   {
     course = "IS2041";
   }//END setAssignCourse
   
   public final void setAssignSctn(String section)
   {
     section = "01T";
   }//END setAssignSctn
   
   public final void setAssignType(String type)
   {
     type = "Lab 02 Classes and Objects";
   }//END setAssignType
   
   public final void setAssignDue(int due)
   {
     due = 20200609;
   }//END setAssignDue
   
   //Get accessor methods for variables
   
   public final String getAssignCourse()
   {
     return course;
   }
   public final String getAssignSctn()
   {
     return section;
   }
   public final String getAssignType()
   {
     return type;
   }
   public final int getAssignDue()
   {
     return due;
   }
   
   
   //Begin toString method for formatting object into string
   public String toString()
   {
     return String.format("Assignment instantiated with full constructor: %n"
                            + "A(n) %s is due on %d for %s.%s", getAssignType, getAssignDue,
                          + getAssignCourse, getAssignSctn);
   }//End toString Format
}
java this getter setter cannot-find-symbol
1个回答
0
投票

应该像getAssignType()那样调用方法,而不是getAssignType

© www.soinside.com 2019 - 2024. All rights reserved.