English 中文(简体)
为什么没有哪一种名称与类别相同的方法?
原标题:Why does a method with the same name as the class not need a return type?
  • 时间:2011-04-22 21:11:11
  •  标签:
  • java

为什么这样做?

public class TwoFrames extends JFrame {
    public TwoFrames() {
        return;
    };
}

而且,这种编号(Net Beans IDE 的话:invalid methods declaration; Return打字要求)?

public class TwoFrames extends JFrame {
    public firstFrame() {
        return;
    };
}
最佳回答

这是一个构造者。 该物体一开始即被点名。 例如:

TwoFrames twoFrames = new TwoFrames();

与常规方法不同的是,建筑商没有回报任何价值。 为什么?

此外,施工人必须把same name作为班级。

希望有助于你们。

问题回答
public class TwoFrames extends JFrame {
    public TwoFrames() {
        return;
    };
}

这实际上是 。 停火者声明像方法一样,但并没有返回类型。 严格说来,尽管你可以不时听到“施工方法”。

一种名称与班级相同的方法是构造者,在制造班子时就叫作。

具有不同名称的方法必须具有返回类型,即使其无效。

它有返回类型,但没有姓名。 这是因为它回到了班级和班级。 当你使用<代码>新关键词时,即指该方法所附内容。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签