相关疑难解决方法(0)

从构造函数调用方法

请原谅任何小的语法错误或诸如此类的错误,我正在通过Jitsi模块遇到这个问题并且不熟悉Java,想要确认发生了什么以及为什么以及如何修复它.

 public abstract class A
{
  public A()
  {
    this.load();
  }

  protected void load()
  {

  }
}

public class B extends A
{
  private String testString = null; 

  public B()
  {
    super();
  }

  @Override
  protected void load()
  {
    testString = "test";
  }
}
Run Code Online (Sandbox Code Playgroud)

应用程序在使用按名称加载类方法创建类B的实例时执行此操作:

  • 在B类中调用重写的load()
  • 初始化变量(根据调试器调用"private string testString = null"),将它们清零.

这是预期的Java行为吗?什么可能导致这个?它是在1.7 JDK上运行的Java 1.6应用程序.

java constructor class

22
推荐指数
2
解决办法
2万
查看次数

Java编译器整数错误

我有这个出现在测验中的代码

public class Main {
  public static void main(String[] args) {
    class b {
      int i = 32;
      b() { b(); }
      void b() { System.out.println(++i); }
    }

    class d extends b {
      int i = 8;
      d() {}
      void b() { System.out.println(--i); }
    }

    b b = new d();
  }
}
Run Code Online (Sandbox Code Playgroud)

输出应该是什么?原来答案是-1,而我预计它是7。java 坏了吗?

java

2
推荐指数
1
解决办法
179
查看次数

标签 统计

java ×2

class ×1

constructor ×1