Task 2:
- Create a class called 'Shop'
- Create below static variables: static int doorNo = 5; static int discount = 10; 2.1. Create below non-static variables int price, weight;
- Create main method.
- Inside main method, create instance as below Shop product1 = new Shop(); Shop product2 = new Shop();
- Using product1, assign price and weight.
- Using product2, assign price and weight.
- Call a non-static method as below. product1.bill(); product2.bill();
- Save, Compile and fix the error.
- Inside bill() method, print price and weight.
- Inside main method and inside bill() method, print doorNo and discount
public class Shop
{
static int doorNo = 5;
static int discount = 10;
int price,weight;
public static void main(String[] args)
{
Shop product1 = new Shop();
Shop product2 = new Shop();
product1.price = 550;
product1.weight = 1000;
product2.price = 150;
product2.weight = 50;
System.out.println("Doorno:"+doorNo+ " Discount:"+discount);
product1.bill();
product2.bill();
}
public void bill()
{
System.out.println("Price:"+price+ " Weight:"+weight);
}
}
Output:
Top comments (0)