[英]Why is this java code not running the class and printing the values? I have tried a lot but not able to find a way out
class pizza {
public int pizza (int price, int discount) {
int total = 0;
total = price - discount;
return total;
}
}
public class MyClass {
public static void main(String[] args) {
int itemNum;
int price;
String pizName;
boolean extraCheese;
itemNum = 1101;
pizName = "Pepperoni";
extraCheese = false;
System.out.println ("Your order a" +pizName+ "pizza will be served shortly.");
pizza pepperoni = new pizza (50, 10);
System.out.println("Your payment without discount is:" + pepperoni.price);
}
}
This is my code above any help would be appreciated.这是我上面的代码,任何帮助将不胜感激。 Thank you so much guys.
十分感谢大家。 Java is a general-purpose computer-programming language that is concurrent, class-based, object-oriented, and specifically designed to have as few implementation dependencies as possible.
Java 是一种通用计算机编程语言,它是并发的、基于类的、面向对象的,并且专门设计为具有尽可能少的实现依赖性。
The name of the method and class should not be same.方法和类的名称不应相同。 You are trying to initialise instance variable using constructor.
您正在尝试使用构造函数初始化实例变量。 But the syntax for the constructor is not correct and also it implicitly returns reference to the object.
但是构造函数的语法不正确,并且它隐式地返回对对象的引用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.