class Weather{
int humidity;
//default value is 0;
}
class Rainy extends Weather{
void changeHumidity(){
humidity = 10;
System.out.println("The humidity is " + super.humidity);
}
}
public class Test{
public static void main(String[] args){
new Rainy().changeHumidity();
System.out.println(new Weather().humidity);
}
}
Here the output is : The humidity is 10 and 0
why super.humidity returns 10.I know that instance variable are not inherited but they can be accessed in sub class.If they can be accessed in sub class then does that means that they are shared between super class and subclass or both super class and subclass have different copy.Now coming to question why super.humidity returns 10 but in next line it returns 0.Kindly make my concept clear please.
Rainywhich is immediately discarded, and oneWeatherwhich is used to printhumidityand also immediately discarded.