静态在主类java和非静态构造函数 [英] static in the main class java and non static in constructor

查看:168
本文介绍了静态在主类java和非静态构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是试图看看我是否可以完全理解静态的概念和静态在一个主类的原因。关键字static指的是主类。主类中的方法是静态的原因是因为主类不处理对象,而是处理类本身。

I'm just trying to see if I can fully understand the concept of static and the reason of static in a main class. The keyword static refers to the main class. the reason why methods in a main class are static is because the main class does not deal with objects but with the class itself.

然而,构造函数处理对象,因此使用非静态构造函数,因为对象具有唯一的特征,使它们静态是没有意义的。

However constructors deal with objects and therefore uses non static constructors because objects have unique characteristics and it would not make sense to make them static.

如果任何人可以看到我在我的陈述中犯了一个错误,或者能引导我朝正确的方向,这将帮助我很多! :)

If anyone can see if I made a mistake in my statement or can steer me in the right direction, it would help me a great deal! :)

推荐答案


我只想看看是否能完全理解静态以及主类中静态的原因。

I'm just trying to see if I can fully understand the concept of static and the reason of static in a main class.

Java中没有主类。

There is no such thing as a main class in Java.


关键字static指的是主类。

The keyword static refers to the main class.

否,它指静态类或静态类成员。

No, it refers to static classes or static class members.


主类中的方法是静态的原因是因为主类不

The reason why methods in a main class are static is because the main class does not deal with objects but with the class itself.

没有类作为主类。该语句是无意义的。

There is no such thing as a main class. The statement is meaningless.


然而,构造函数处理对象,因此使用非静态构造函数,因为对象具有唯一的特性,

However constructors deal with objects and therefore uses non static constructors because objects have unique characteristics and it would not make sense to make them static.

所有构造函数都是非静态的。没有像静态构造函数这样的东西。

All constructors are 'non-static'. There is no such thing as a static constructor. There is no point in any of this discussion.


如果任何人可以看到我在我的陈述中犯了一个错误,或者可以引导我在正确的方向,它会帮助我很大! :)

If anyone can see if I made a mistake in my statement or can steer me in the right direction, it would help me a great deal! :)

我想你需要重新开始,忘记了不存在的'主类'和'静态构造函数'。基本上静态方法指的是可以在没有类的实例的情况下调用的方法。相反,构造函数创建了类的实例,因此它们在逻辑上不能是静态的。

I think you need to start again, forgetting about non-existent 'main classes' and 'static constructors'. Basically static methods refer to methods that can be invoked without having an instance of the class. Conversely, constructors create an instance of the class so they can't logically be static.

这篇关于静态在主类java和非静态构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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