2

我被要求“识别 Java 中的所有语言结构。您的列表应以类开头:

类声明的主体"

我的印象是“语言结构”是一种语言中任何允许的命令,但这显然不是问题的意思。如果有人能让我更清楚地了解这种情况下的语言结构是什么,以及这个列表应该包含什么样的东西,我将不胜感激。

提前致谢!

4

3 回答 3

3

Well, according to Wikipedia, a language construct is "a syntactically allowable part of a program that may be formed from one or more lexical tokens in accordance with the rules of a programming language"

The phrase "language construct(s)" appears in the JLS once, in the Preface (excluding a mention in the index): "We intend that the behavior of every language construct is specified here..." This implies that every Java "language construct" is cataloged in the JLS. Combined with the Wikipedia definition, that would seem to cover everything from keywords and literal values; types, names, and variables; to packages, classes, interfaces, and class members like methods, fields, and constructors; blocks, statements, expressions... Take your pick. Just take a look through the ToC.

于 2011-09-27T03:10:37.263 回答
1

在我看来,他的意思是问“在类声明的主体中允许什么?” 在普通的 Java 中,会是这样的:

  • 一个类可能同时包含“成员”和静态块。
  • 成员可以是公共的、受保护的、包私有的或私有的。
  • 成员可以静态或非静态访问
  • 成员可能是以下人员之一:
    1. 多变的
    2. 方法
    3. 内部类
  • 一个变量后面可以跟一个赋值。
  • 一个方法可能包含一系列对其他方法的调用、变量声明和变量赋值。
  • 最后,内部类可能包含上面列出的所有内容,因为它本身就是一个普通类。
于 2011-09-27T03:18:59.663 回答
0

我希望你会知道什么是构造。

因此,让我告诉您 Java 中允许的构造类型:

  1. 序列结构——在这个程序中从一个地方开始并逐行执行(每一行都在这部分代码中执行)。
  2. 选择结构——在这个结构中,我们有两个或两个以上的语句或代码的一部分,并且根据条件(例如,if else)仅执行有限的或一个。
  3. 循环结构 - 在此,一组语句被一次又一次地重复(部分代码被一次又一次地重复)。

这种分类是基于执行代码时编译器或解释器所遵循的路径。

希望能帮助到你。

于 2016-09-29T00:00:40.257 回答