English 中文(简体)
1. 与身为外产阶级的内产阶级
原标题:Coding an inner class with Point as outer class

对于一项派任,我需要从java.awt的班子内设立一个班级。 点。 我需要能够使用点方法,同时为内心/内nes的阶层创造我自己的变量。 我感到困惑的是,静态nes的班级和内班级之间的差异,以及人们知道哪些人使用。 我曾试图使用静态的舱位,并遇到一个错误,称“此处不允许静态”

我的误导企图:

class Point {
    static class RobotJAW {

        int goldcollected, x, y;

        RobotJAW() {
            goldcollected = 0;
            alive = true;
            x = 0;
            y = 0;
        }

    }
}

创建这一阶层是为了在被炸弹摧毁时,进行机器人搜索,寻找黄金和炸弹,收集黄金。 我只能使用黑体字标语和斯堪纳语。 我需要使用点方法等于(obj)、移动(int x, int y)、移动(toLocation()和定位(int x, int y)。 但是,我需要增加收集的黄金和活着的变量。 此外,这是学校的一项任务,因此,我希望更多地了解这个主题,并提出一些指导,而不要给其他人工作。

最佳回答

A lesson about how inner classes work, then some doubts that that is what you really need. An inner class is used for describing a class with an extremely strong belongs-to relationship to another class. So strong infact, that it cannot survive without the outer class. So strong, that you rarely need it. The inner class is only accessible through an instance of the outer class:

public class A{
  public int value1;
  public class B{
    public int value2;
  }
}
...
A a1 = new A()
a1.value1 = 202
A.B b1 = new a1.B();
System.out.println(b1.value1); //Prints 202
A.B b2 = new B(); //Compiler error! Not allowed

静态内产阶级实际上不是内产阶级。 这只是内部班子内界定的一类。

它看上去你想要的机器人Jaw,要么是,要么是,要么是,要么是。 你们不想把它当作一个不容置疑的物体。 因此,机器人司法办公室要么延伸点,要么包含点。

问题回答

对于一项派任,我需要从java.awt的班子里设立一个班级。 点。

只有当你有外产阶级的源代码并能够补齐时,你才能在班子内开设一个班级。 可在java.awt.Point上填写。

如果你认为你的职责是telling。 你这样做,你是可证明是错解释你的职责。

当然,在<条码><>点/代码>内设立带宽的班级,并不具有意义。 AFAIK认为,点上加固的等级不能由非封闭的阶层来做。 或许在请您填写<编码>extend。 www.un.org/Depts/DGACM/index_french.htm 班级,即设立子级,而不是门类。


(从理论上讲,这样做是可能的,但并非纯粹的 Java;例如

  • You可下载开放JDK的源码,将你的nes子添加到 j。 点击和重建。 但归根结底,是NOT Java.

  • You can use bytecode magic tobuilding a categoryfile for a nested category. 如果你正确的话,它就能够装上,而且(我认为)它能够查阅外部类别的私人方法和属性。 但这不是纯 Java。

<分> 两种办法完全坏了,这几乎肯定不是你所期望的。”





相关问题
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 ...

热门标签