gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 07:15:25 28 4
gpt4 key购买 nike

首先,我不是要求任何人做我的作业。我只是对这个 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/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com