Q:

Subclass is not returning the value - Java

I'm newbie to core java. I'm studying java myself. I've learned some basic stuffs in java. Now i'm working out inheritance concept. I wrote a code create two class. One is a superclass called "Inhersam" and another one is subclass called "subclass". I've created a function getgid() in subclass and i'm trying to call that function from superclass. Hello World!!! string is printing, but function is not returning any value. what is the problem?
class subclass
{
    int getgid()
    {
        return 31;
    }

}
public class Inhersam extends subclass
{

    public static void main(String[] args)
        {
            Inhersam l=new Inhersam();
            /*subclass l=new subclass();*/
            l.getgid();
            System.out.println("Hello World!!!");
        }

}

A:

Short answer: The reason "31" is not being printed in the console is because you didnt put the function inside System.out.println().
Also, I find a bit weird that you are creating an instance of the class you're already in, You shouldnt have to do this Inhersam l=new Inhersam(); just calling getgid() would do the job, as you are already defining the method in its parent class.. (just make sure to define the access modifier to be protected) like this: protected int getgid() {}
This is how your code should look:
class subclass
{
    protected int getgid()
    {
        return 31;
    }

}
public class Inhersam extends subclass
{

    public static void main(String[] args)
        {
            System.out.println("Hello World!!!" + getgid());
        }

}

