如何从另一个类获取私有字段?

coo*_*ook 0 java

我有一个名为date的课程:

public class Date{
    private String monthAndDate;
    public Date(String inputMonthAndDate){
        monthAndDate = inputMonthAndDate;
    }
}
Run Code Online (Sandbox Code Playgroud)

我有另一个名为Patient的课程.是否可以从Date类获取monthAndDate的语法并将其传递给Patient类中的私有字段?

谢谢.

Lou*_*man 6

并非没有为你的Date班级添加一个吸气剂.这就是部分制作领域私人的.