Pre Exam Test Practice (SSC | Banking | IAS | GATE | State Level | CLAT | Railways | Insurance | Teaching Exams | NDA | Defence | IES |State Exam )

Organizational Research By

Surprising Reserch Topic

is there a way to override class variables in java


is there a way to override class variables in java  using -'java,inheritance,override'

class Dad
{
    protected static String me = "dad";

    public void printMe()
    {
        System.out.println(me);
    }
}

class Son extends Dad
{
    protected static String me = "son";
}

public void doIt()
{
    new Son().printMe();
}


The function doIt will print "dad". Is there a way to make it print "son"?
    

asked Sep 10, 2015 by BusIOSA
0 votes
13 views



Related Hot Questions



Government Jobs Opening


...