这是类,构造函数还是方法? [英] Is this a class, constructor, or method?

查看:56
本文介绍了这是类,构造函数还是方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难确定这到底是什么.在这一点上,我熟悉方法,构造函数和类声明的外观.这是哪一个为什么它看起来像一个构造函数和一个方法有一个婴儿?

I'm having trouble identifying what exactly this is. At this point, I am familiar with what methods, constructors, and class declarations look like. Which is this? Why does it look like a constructor and a method had a baby?

public Polygon polygonFrom(Point[] corners) {  
// method body goes here
}

推荐答案

您所拥有的是一种方法

为什么?

在Java中,方法声明按顺序包含五个组件:

In Java, method declarations have five components, in order:

  1. 修饰符,例如 public private 以及其他您稍后将了解的修饰符.
  2. 返回类型-方法返回的值的数据类型;如果方法未返回值,则返回 void .
  3. 方法名称-字段名称的规则也适用于方法名称,但约定略有不同.
  4. 括号中的参数列表-输入参数的逗号分隔列表,其输入的数据类型由括号()括起来.如果没有参数,则必须使用空括号.
  5. 方法主体,括在花括号之间,该方法的代码(包括局部变量的声明)在此处.
  1. Modifiers—such as public, private, and others you will learn about later.
  2. The return type—the data type of the value returned by the method, or void if the method does not return a value.
  3. The method name—the rules for field names apply to method names as well, but the convention is a little different.
  4. The parameter list in parenthesis—a comma-delimited list of input parameters, preceded by their data types, enclosed by parentheses, (). If there are no parameters, you must use empty parentheses.
  5. The method body, enclosed between braces—the method's code, including the declaration of local variables, goes here.

public Polygon polygonFrom(Point[] corners) {  
// method body goes here
}

分析您的代码段:

1 .公共是修饰符

2 .多边形是返回类型

3 .plygonForm是方法名称

3. plygonForm is method name

4 .(Point []角)是括号中的参数列表

4. (Point[] corners) is the parameter list in parenthesis

5 .{}是方法主体

这篇关于这是类,构造函数还是方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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