Create a class called SuperMarket. Assign 2 static variables. Then create 3 Objects. Two objects with 2 arguments. One object with 3 arguments. Then print all the details.
public class SuperMarket{
//static variables
static String superMarketName = "Grace Supermarket";
static int superMarketDoorno = 150;
//non - static variables
String name;
int price;
int discount;
//creating constructor with 2 parameters
public SuperMarket(String name, int price){
this.name = name; //using this keyword
this.price = price;
}
//creating constructor with 3 parameters
public SuperMarket(String name, int price, int discount){
this.name = name;
this.price = price;
this.discount = discount;
}
public static void main(String[] args){
//creating objects with 2 arguments
SuperMarket m1 = new SuperMarket("Milk", 25);
SuperMarket m2 = new SuperMarket("Curd", 20);
//creating objects with 3 arguments
SuperMarket m3 = new SuperMarket("Dal", 250, 10);
System.out.println(SuperMarket.superMarketName);
System.out.println(SuperMarket.superMarketDoorno);
System.out.println(m1.name);
System.out.println(m1.price);
System.out.println(m2.name);
System.out.println(m2.price);
System.out.println(m3.name);
System.out.println(m3.price);
System.out.println(m3.discount);
}
}
Output:
Grace Supermarket
150
Milk
25
Curd
20
Dal
250
10
Top comments (0)