在我的课程中,双尖括号在Java中是什么意思?

时间:2019-07-08 17:12:32

标签: java

我尝试使用我从类继承中学到的知识,但出现错误。因此,我尝试在Eclipse中找到它,并说我需要将类中的{...}翻倍为{{...}}。有人可以解释什么意思吗?

以下是带有问题的代码:

final class Brot extends Lebmit{{
id = 1;
preis= (float)1.15;
haltetD=20;
vorhanden=true;
art = "Lebensmittel";

}}

以下是超类:

abstract class Waren{
protected float preis;
protected boolean vorhanden;
protected String art;
protected int id;

abstract void anzeigen();
}

abstract class Lebmit extends Waren{
protected int haltetD;


protected void anzeigen(){
System.out.println("Id: "+id);
System.out.println("Produckt: "+art);
System.out.println("Preis: " + preis);
System.out.println("Haltet noch "+haltetD+" Tage");
if(vorhanden){
    System.out.println("Das Produkt ist Verfügbar");
  }else {
    System.out.println("Das Produkt ist \"nicht\" Verfuegbar");
  }

 }
}

主类:


public class Geschaeft{
 public static void main(String [] args){

  Brot das= new Brot();
  das.anzeigen();

 }

}

0 个答案:

没有答案