如何从另一个类调用方法? [英] How do I call a method from another class?

查看:118
本文介绍了如何从另一个类调用方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打印另一个类中的方法.我怎么做?

I want to print a method that is in another class. How do I do that?

谢谢!

我要调用的方法名称是 FoodMenu类中的public void printMenu()....

The method name I am trying to call is public void printMenu()... within a class called FoodMenu.

推荐答案

创建FoodMenu的实例并使用它来调用printMenu()

Create an instance of FoodMenu and use it to call printMenu()

FoodMenu foodMenu = new FoodMenu();
foodMenu.printMenu();

这篇关于如何从另一个类调用方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆