tag:blogger.com,1999:blog-8712770457197348465.post1222412358849110601..comments2024-03-18T22:23:44.692-07:00Comments on Javarevisited: Can You Overload or Override Static methods in Java? Examplejavin paulhttp://www.blogger.com/profile/15028902221295732276noreply@blogger.comBlogger11125tag:blogger.com,1999:blog-8712770457197348465.post-51296678532968711742017-01-05T05:39:33.397-08:002017-01-05T05:39:33.397-08:00its correct!its correct!Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-41076573021835751362015-12-17T01:56:04.110-08:002015-12-17T01:56:04.110-08:00Hello ,
I would like to know whether it is "...Hello ,<br /><br />I would like to know whether it is "CORRECT" to call static method using objects of the class.<br /><br />Though it is certainly possible, does it not defeat the whole purpose of static modifier.<br /><br />"Static" is always associated with a class rather than its object.<br /><br />Please correct me if I am wrong, however I felt compelled to post my query.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-37915319098182931102015-10-02T04:59:17.319-07:002015-10-02T04:59:17.319-07:00@AlienOnEarth, it's not overriding but hiding,...@AlienOnEarth, it's not overriding but hiding, static variables are resolved at compile time by using Type of variable, Sine you are accessing them in TestParent class, it's print "test"javin paulhttps://www.blogger.com/profile/15028902221295732276noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-65399360989530950552015-10-01T21:04:05.961-07:002015-10-01T21:04:05.961-07:00I tried to override static variable in Java 7. I a...I tried to override static variable in Java 7. I am able to do it. <br /><br />public class TestStatic {<br /> <br /> protected static String name = "MockingJay";<br /> <br />}<br /><br />public class TestParent extends TestStatic{<br /><br /> protected static String name = "test";<br /> <br /> public static void main(String[] args) {<br /> <br /> <br /> System.out.println(AlienOnEarthhttps://www.blogger.com/profile/06516016268821298693noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-87287435750329119452013-09-21T06:00:43.841-07:002013-09-21T06:00:43.841-07:00 Method Overriding VS Method Hiding in java
If ... Method Overriding VS Method Hiding in java<br /><br /><br /><br />If and instance method in a subclass has same signature and return type as instance method in the superclass ,it is called overriding.Method signature means name, and the number and the type of its parameters. Number ,type of the parameters should be same in method written in super class and sub class.<br /><br /> overriding MANOJ KUMARhttps://www.blogger.com/profile/00421517842858762886noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-43436282270469075882013-03-21T00:26:19.789-07:002013-03-21T00:26:19.789-07:00@Anonymous, Thanks for kind words, and I am glad t...@Anonymous, Thanks for kind words, and I am glad that you find this Java Blog useful.<br /><br />JavinJavin @ Java Classloder Workinghttp://javarevisited.blogspot.com/2012/12/how-classloader-works-in-java.htmlnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-17209994119703165662013-03-21T00:25:18.385-07:002013-03-21T00:25:18.385-07:00@born2perform, Indeed, that's a useful check a...@born2perform, Indeed, that's a useful check and one of the java coding best practice, I have shared few tips on <a href="http://javarevisited.blogspot.co.uk/2012/11/why-use-override-annotation-in-java.html" rel="nofollow">@Override annotation in Java</a>, you may like. By the way, with static methods, you can not use @Override annotation, it's compilation error.Javin @ Connection refused exception in Javahttp://javarevisited.blogspot.com/2013/02/java-net-ConnectException-Connection-refused.htmlnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-1250858627363743062013-03-18T15:39:32.982-07:002013-03-18T15:39:32.982-07:00In Java 1.5 or greater, you can use @Override anno...In Java 1.5 or greater, you can use @Override annotation to see whether you are 'really' overriding the method. It's a free check by the compiler.Anonymousnoreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-61526712807621595772013-03-18T09:52:36.452-07:002013-03-18T09:52:36.452-07:00Java doesn't allow overriding of static method...Java doesn't allow overriding of static methods..<br />class stat13<br />{<br /> static void show()<br /> {<br /> System.out.println("Static in base");<br /> }<br /> public static void main(String[] ar)<br /> {<br /> new next().show();<br /> }<br />}<br /><br /><br />class next extends stat13<br />{<br /> static void show()<br /> {<br /> SARAL SAXENAhttps://www.blogger.com/profile/01084233786047386880noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-53285752058987211552013-03-18T09:49:13.538-07:002013-03-18T09:49:13.538-07:00Overriding depends on having an instance of a clas...Overriding depends on having an instance of a class. The point of polymorphism is that you can subclass a class and the objects implementing those subclasses will have different behaviors for the same methods defined in the superclass (and overridden in the subclasses). A static method is not associated with any instance of a class so the concept is not applicable.<br /><br />There were two SARAL SAXENAhttps://www.blogger.com/profile/01084233786047386880noreply@blogger.comtag:blogger.com,1999:blog-8712770457197348465.post-71820691279181896652013-03-18T06:13:28.056-07:002013-03-18T06:13:28.056-07:00I faced this question 2 times during my interview....I faced this question 2 times during my interview. Happy to see it here. I know the answer but I am glad to see it with example. :)Shailesh Jangrahttp://www.studynfun.wordpress.comnoreply@blogger.com