This theme is built|

Little_Monster-lhq

园龄:5年9个月粉丝:26关注:18

📂JavaSE
🔖Study
2022-09-10 09:46阅读: 408评论: 0推荐: 0

JAVA中方法的调用主要有以下几种

JAVA中方法的调用主要有以下几种:
1.非静态方法
非静态方法就是没有 static 修饰的方法,对于非静态方法的调用,是通过对 象来调用的,表现形式如下。

对象名.方法()
eg:

public class InvokeMethod{
public static void main(String[] args){
InvokeMethod in = new InvokeMethod();
in.t1();
}
public void t1(){
System.out.printfln("t1");
}
}

2.调用静态方法
静态方法就是用 static 修饰的方法,静态方法的调用是通过类名来调用的, 表现形式如下:

类名.方法()
eg:

public class InvokeMethod{
public static void main (String[] args){
InvokeMethod.t2();
}
public static void t2(){
System.out.println("static t2....");
}
}

3.方法与方法之间的调用
方法与方法之间的调用,主要是在一个方法内部如何调用其他方法。
(1)静态方法内部调用其他方法
如果在本类当中,静态方法可以直接调用静态方法,
除了在 main 方法中,还可以在自定义的静态方法中直接调用。
如果在本类当中是非静态方法,就必须通过对象来调用。

public class InvokeMethod{
public static void main (String[] args){
t2();
}
public static void t2(){
System.out.println("static t2...");
}
public static void t1(){
//静态方法调用非静态方法需通过对象来调用
//InvokeMethod in =new InvokeMethod();
//in.t2();
t2();
System.out.println("static t1");
}
}

如果不在一个类当中,静态方法调用其他类中的静态方法,必须通过
类名.静态方法();

如果在不同类当中,静态方法调用其他类的非静态方法,需要导入该类中的包,以及通过创建对象调用。

(2)非静态方法内部调用
如果在本类中,非静态方法可以直接调用静态方法与非静态方法。
在不同类中,非静态方法调用其他类的静态方法,需要通过导入该类中的包,并且需要通过类名来调用
在不用类中,非静态方法调用其他类的非静态方法时,需要导入该类中的包,还需要通过创建对象来调用。

本文作者:Little_Monster-lhq

本文链接:https://www.cnblogs.com/little-monster-lhq/p/16676064.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   Little_Monster-lhq  阅读(408)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起
  1. 1 IVORY TOWER - 虞万殊
  2. 2 I Really Like You - Carly Rae Jepsen
  3. 3 404 not found REOL
  4. 4 不暧昧 - 徐秉龙,黄星侨
IVORY TOWER - - 虞万殊
00:00 / 00:00
An audio error has occurred, player will skip forward in 2 seconds.

IVORY TOWER

词:Benjamin/mpi

曲:泽野弘之

编曲:泽野弘之

原唱:SennaRin

音乐协力:LUNA KINGDOM株式会社

翻唱/后期:虞万殊

It's not easy lose my grip those dreams are calling me

Like a hermit used to find a reason not to be

You teach me about the history of our fallen heroes

Realize I have found a solid companion

Cos

I was afraid

Was alone

In a cave

Like a stone

This

Dance is so dangerous

So cryptic it changes us

But the secrets that we learn

Can give power to all of us

Dance shook me dangerous

So glad that you came to us

Can a lesson that we learn transform our view

Do you hear me

Destination I

Gotta invitation I

Gonna change all my sense

Of reality

Gonna change reality

Come on my

Destination I

Got my information I

Gonna change all my sense

Of reality

Gonna change reality

In too deep

When did we pass the point of no return

A new way to slay the beast

We're gonna beat the burn

Don't think twice keep on pounding on the wall till it shatters

Turn the tide

Gotta climb the ladder that matters

Cos

I was afraid

Was alone

In a cave

Like a stone

This

Dance is so dangerous

So cryptic it changes us

But the secrets that we learn

Can give power to all of us

Dance shook me dangerous

So glad that you came to us

Can a lesson that we learn transform our view

Do you hear me

Destination I

Gotta invitation I

Gonna change all my sense

Of reality

Gonna change reality

Come on my

Destination I

Got my information I

Gonna change all my sense

Of reality

Gonna change reality

Can hear them calling

Can hear them calling

Can hear them calling

Can hear them

Fight for us

Can hear them calling from towers that we trust

Can feel the legacy grow and

So we must

Stand together

Be tight

Making everything right

Empowers you to be strong

Do you hear me

Destination I

Gotta invitation I

Gonna change all my sense

Of reality

Gonna change reality

Come on my

Destination I

Got my information I

Gonna change all my sense

Of reality

Gonna change reality