This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
NOTE: You can use Animal reference to access protected member within package p, but not outside package p.
if you want to access x then just use x to access it or this.x. But mind it, static context cannot have reference to any non-static context. Thats
why in the above code (by Abimaran ) x is accessed through Dog object. The following code is also legitimate and in this code we would use just
The above code just compiles well ,But in order to print the value of x, you have to define main(String args) method which would call main() method above
by the use of some instance of Dog class.
One more Tip : We can have main() method, this is an overloaded method and you would study it in later chapters.
NOTE: After grasping the above concept, try answering the following question, but before attempting it do not forget to read the rules given as a link in the same.