java - 这段Java代码是什么意思?

标签 java abstract-class

首先,我不是要求任何人做我的作业。我只是对这个 Java 语法感到困惑。

下面是作业描述和我必须实现的两个类。第一个仅供引用。 第二个是我遇到问题的。

Being able to program with numbers that do not (in theory) have a maximum value is a necessity in many applications of computer science. You are going to write a series of classes to get started on this task. Your final class will allow you to represent and at least add Binary numbers of arbitrary length.

// You are to write (implement) this class exactly as dictated by the following list of class members.
public abstract AbstractBit: 

  private boolean bit;

  public abstract AbstractBit clone(); 
  public abstract AbstractBit addBits(AbstractBit guest);
  public abstract AbstractBit addBits(AbstractBit guest1, AbstractBit guest2);
  public abstract AbstractBit carryBit(AbstractBit guest);
  public abstract AbstractBit carryBit(AbstractBit guest1, AbstractBit guest2);

  protected void setBit(boolean value)

  public boolean getBit()

  public AbstractBit()

  public AbstractBit(boolean value)

  public AbstractBit(AbstractBit guest)

  public boolean equals(AbstractBit guest)

  public String toString()

这些到底是什么?

为什么要添加 BinaryBit 类型的静态类变量?这不是会以某种方式递归吗? (参见标有 ??? 的行)

// You are to write (implement) this class exactly as dictated by the following list of class members.
public BinaryBit extends AbstractBit: 

  public static final BinaryBit zero = new BinaryBit(false);  // ????
  public static final BinaryBit one = new BinaryBit(true);    // ????

  public BinaryBit()

  public BinaryBit(boolean bit)

  public BinaryBit(int bit)

  public BinaryBit(BinaryBit guest)

  public BinaryBit clone()

  public boolean equals(BinaryBit guest)

  public String toString()

  public AbstractBit addBits(AbstractBit guest)

  public AbstractBit addBits(AbstractBit guest1, AbstractBit guest2)

  public AbstractBit carryBit(AbstractBit guest)

  public AbstractBit carryBit(AbstractBit guest1, AbstractBit guest2)

最佳答案

这是仅存在有限数量的实例时使用的技术。它们都被声明并被称为常量。传统上将它们称为“零”和“一”,以使其更明显地表明它们是常数。它实际上不是递归的,因为静态变量只创建一次。

关于java - 这段Java代码是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4200857/

相关文章:

java - 具有默认值的 Android 项目的 AndroidManifest.xml 文件中的错误

C# 反序列化未知抽象类

java - Java会自动调用抽象类的构造函数吗?

PHP - 如果抽象类中的所有方法都是抽象的,那么接口(interface)和抽象类之间有什么区别

java - 如何在json和java中创建子项,以及如何在javascript中获取子项的值?

java - 使用正则表达式检查字符串是否仅包含数字并且数字不相同?

java - 用于构建的 Android Studio 设置节点目录(原因 : error=2, No such file or directory)

c# - 仅部分实现抽象类的接口(interface)时如何满足编译器?

Java:在抽象类中创建获取扩展类名称的方法

java - 正则表达式(regex)。如何忽略或排除之间的一切?