我是一名AP Java学生,我正在练习考试.我遇到了这个问题,我不明白答案:
考虑以下类:
public class A
{
public A() { methodOne(); }
public void methodOne() { System.out.print("A"); }
}
public class B extends A
{
public B() { System.out.print("*"); }
public void methodOne() { System.out.print("B"); }
}
Run Code Online (Sandbox Code Playgroud)
执行以下代码时的输出是什么:
A obj = new B();
Run Code Online (Sandbox Code Playgroud)
正确的答案是B*.有人可以向我解释一下方法调用的顺序吗?
我正在编写一个程序作为初学者Java学生的教程的一部分.我有以下方法,每当我运行它时,它给我以下异常:
java.util.ConcurrentModificationException
at java.util.AbstractList$Itr.checkForComodification(AbstractList.java:372)
at java.util.AbstractList$Itr.next(AbstractList.java:343)
at Warehouse.receive(Warehouse.java:48)
at MainClass.main(MainClass.java:13)
Run Code Online (Sandbox Code Playgroud)
这是方法本身,在类Warehouse中:
public void receive(MusicMedia product, int quantity) {
if ( myCatalog.size() != 0) { // Checks if the catalog is empty
// if the catalog is NOT empty, it will run through looking to find
// similar products and add the new product if there are none
for (MusicMedia m : myCatalog) {
if ( !m.getSKU().equals(product.getSKU()) ) {
myCatalog.add(product);
}
}
} else { // if the catalog is empty, …Run Code Online (Sandbox Code Playgroud)