实例方法的示例? (JAVA) [英] Example of an instance method? (Java)

查看:394
本文介绍了实例方法的示例? (JAVA)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我还在学习Java中的方法,并且想知道你如何使用实例方法。我在考虑这样的事情:

I'm still learning about methods in Java and was wondering how exactly you might use an instance method. I was thinking about something like this:

public void example(String random) {
}

但是,我不确定这实际上是实例方法还是其他类型的方法。有人可以帮帮我吗?

However, I'm not sure if this is actually an instance method or some other type of method. Could someone help me out?

推荐答案

如果它不是静态方法那么它就是一个实例方法。这是一个或另一个。所以是的,你的方法,

If it's not a static method then it's an instance method. It's either one or the other. So yes, your method,

public void example(String random) {
  // this doesn't appear to do anything
}

是一个实例方法的例子。

is an example of an instance method.

关于


并想知道你如何使用实例方法

and was wondering how exactly you might use an instance method

您将创建该类的实例,一个对象,然后在该实例上调用实例方法。 ie,

You would create an instance of the class, an object, and then call the instance method on the instance. i.e.,

public class Foo {
   public void bar() {
      System.out.println("I'm an instance method");
   }
}

可以像:

Foo foo = new Foo(); // create an instance
foo.bar(); // call method on it

这篇关于实例方法的示例? (JAVA)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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