Sankar Karthi
Sankar Karthi

Reputation: 355

is it possible to print static method?

class DuckPrivate
{
    private static int size;
    public static void main(String [] args)
    {
    Duck d=new Duck();
    d.setSize(25);
    d.getSize();
        System.out.println("size of duck is "+size);
    }
    public static void setSize(int s)
    {
        size=s;
    }
    public static int getSize()
    {
        return size;
    }
}

I am getting the error cannot find the symbol getSize(),why i am getting this error,is it possible to print the static method.

Upvotes: 1

Views: 1212

Answers (1)

Akash Thakare
Akash Thakare

Reputation: 22972

Duck d = new Duck(); you are calling set/getSize method of Duck not DuckPrivate and note d.getSize(); if exist will return the value which you need to store.In DuckPrivate you can simply call setSize(25); as it's static and just print size.

Upvotes: 3

Related Questions