从另一个类调用方法 [英] Call a method from another class
本文介绍了从另一个类调用方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在Main类中调用create()方法,其中create()函数属于Summary类?
我有什么试过:
计算
How can I call create() method in Calculation class from Main class where the create() function belongs to Summary class ?
What I have tried:
Calculation
public class Calculation{
private Summary create(){}
}
Main
Main
Calculation c = new Calculation();
c.create(); // cannot find symbol
推荐答案
您的方法被标记为private
因此它将无法从该类外部访问,将其更改为public
或将其读取为其他修饰符: java中的访问修饰符 - Javatpoint [ ^ ]
Your method is marked asprivate
hence it will not be accessible from outside that class, change it topublic
or read this for other modifiers : Access modifiers in java - Javatpoint[^]
您需要将您的课程视为公开课程而不是私人课程。 Private使它无法在自身之外访问,这将使其无法调用。
You need to have your class as public instead of private. Private makes it to where it cannot be accessed outside of itself, which would make it impossible to call on.
这篇关于从另一个类调用方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文