DEV Community

Kiruthiga S
Kiruthiga S

Posted on

Java

OBJECT
Object is an instance of a class that represents a real-world entity
Used to access the variables and methods defined inside a class

Variable
1.Local
2.Global
-Static
-Non-Static

Static
- Class
- Static will create only one memory

Non-Static
- Object,instance
- Non-Static will depends on the according to the number of products

public class SuperMarket {
   String prod_name="boost";
   int price=250;
    public static void main(String[] args)
    {
        SuperMarket product=new SuperMarket();
        System.out.println(product.prod_name);
        System.out.println(product.price);
    }
}
Enter fullscreen mode Exit fullscreen mode

Output:
boost
250

public class SuperMarket {
   String prod_name1="boost";
   int price1=250;
   String prod_name2="Horlicks";
   int price2=300;
    public static void main(String[] args)
    {
        SuperMarket product1=new SuperMarket();
        System.out.println(product1.prod_name1);
        System.out.println(product1.price1);
        SuperMarket product2=new SuperMarket();
        System.out.println(product2.prod_name2);
        System.out.println(product2.price2);

    }
}
Enter fullscreen mode Exit fullscreen mode

Output:
boost
250
Horlicks
300

Top comments (0)