DEV Community

subash
subash

Posted on

Static and Non-static function


public class Index

{    

    String name;
    int price;
    public static void main (String[] args){
        Index prod1 = new Index();

        prod1.name = "car";
        prod1.price = 200;
        prod1.buy();
    }
    void buy(){
        System.out.println(name);
    }
}

Enter fullscreen mode Exit fullscreen mode

OUTPUT;


public class Index

{    

    String name;
    int price;
    public static void main (String[] args){
        Index prod1 = new Index();

        prod1.name = "car";
        prod1.price = 200;
        Index.buy();
    }
    static void buy(){
        System.out.println("this function is for static");
    }
}
Enter fullscreen mode Exit fullscreen mode

output;

Top comments (0)