tag:blogger.com,1999:blog-694855878384792308.post4366972295390608191..comments2024-03-21T06:26:49.387-07:00Comments on Java67: Can You Override Private Method in Java? Inner Class?javin paulhttp://www.blogger.com/profile/15028902221295732276noreply@blogger.comBlogger8125tag:blogger.com,1999:blog-694855878384792308.post-65505266379973512752020-11-17T20:14:09.475-08:002020-11-17T20:14:09.475-08:00awesome explanation thanks.awesome explanation thanks.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-23653142121570126582015-12-16T03:54:02.078-08:002015-12-16T03:54:02.078-08:00Hello Squeerzer, I agree its not easy to catch bec...Hello Squeerzer, I agree its not easy to catch because of reference of inner and outer class, but let me know if you are not able to understand the example and the concept behind overriding private method, I'll try to explain you here. Let me know your doubtjavin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-64661899666883871202015-12-15T07:24:14.073-08:002015-12-15T07:24:14.073-08:00Confusing explanation of the example :)Confusing explanation of the example :)Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-5858625593465034522013-10-05T16:58:02.545-07:002013-10-05T16:58:02.545-07:00You cleared my doubt regarding private class! nice...You cleared my doubt regarding private class! nice site!npprogrammershttp://www.npprogrammers.blogspot.innoreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-28159221172418141332013-08-18T19:59:49.702-07:002013-08-18T19:59:49.702-07:00I think there are some points, which should have b...I think there are some points, which should have been much clear :<br /><br />1) if first call to showPrivate() method is to demonstrate that private method of Outer class is accessible inside Inner class, than you have to first comment out privateMethod() of NestedClass, which is hiding privateMethod of Outer class. If you do this, than you will get the output :<br /><br />Accessing Private members of Outer class: I am private member, not accessible outside this Class<br />Private method of Outer Class<br /><br />I think, that's what author meant to, by looking at code and output.<br /><br />Now, In second call to private method, which should be outClass.privateMethod(), you need to uncomment privateMethod() in nested class. Now this is what he means by trying to override a private method in Inner class. If you run the code again, you will get output as<br /><br />Private method of Outer Class<br /><br />I hope this make sense.<br /><br /> Regular Readernoreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-50253140425251387812013-08-18T16:44:54.009-07:002013-08-18T16:44:54.009-07:00Also @Override annotation will show error instead ...Also @Override annotation will show error instead of hiding the private methodAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-2905934744580369042013-08-17T22:56:22.958-07:002013-08-17T22:56:22.958-07:00Change nc.privateMethod(); to outerClass.privateMe...Change nc.privateMethod(); to outerClass.privateMethod(); The output will be:-<br />Accessing Private members of Outer class: I am private member, not accessible outside this Class<br />Private method of Nested Class<br />Private method of Outer Class<br />Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-694855878384792308.post-19447748425219612442013-08-17T22:36:48.429-07:002013-08-17T22:36:48.429-07:00But I am getting the below output:
Accessing Priva...But I am getting the below output:<br />Accessing Private members of Outer class: I am private member, not accessible outside this Class<br />Private method of Nested Class<br />Private method of Nested ClassAnonymousnoreply@blogger.com