Talk:Java Programming/Methods

Static Method definitly can be overriden. The only constraint is that it does not suppport polymophism.

Example: class A   { static public void test {	  System.out.println("Inside A"); } } class B  extends A { static public void test {	  System.out.println("Inside B"); } } public class methosover {   public static void main(String[] args) {       A a = new A; B b = new B; a.test; b.test; } } The simple answer is that static methods are associated with the class itself, not with an instance of the class, so when you call test, which version gets called depends on what class you call it on, a.test; or b.test; Output: Inside A Inside B


 * Static methods can be hidden, not overridden. --Spoon! (talk) 07:13, 20 December 2007 (UTC)

Method overriding section
Can somebody fix the section on Method overriding? It's very confusing and I am trying to figure out what it's saying. I have no idea. The grammar is very badly written and the sentences ambiguous. It's not very helpful for trying to learn Java, as I am doing. -68.144.12.65 (talk) 03:46, 18 October 2010 (UTC)
 * Hm actually it's specifically this section:


 * In the above example 'obj' reference has the type MyClass on both line 1 and line 3. However the 'obj' reference points two different objects. On line 1 it references SubOfMyClass object, on line 3 it references MyClass object. So on line 5 which method will be called, method define in MyClass, or the method that defined in its subclasses. Because the 'obj' reference can point to object and all its sub object, and that will be known only at runtime, a table needs to be kept with all the possible method address to be called.


 * Can anyone figure out what they're trying to say there? -68.144.12.65 (talk) 03:49, 18 October 2010 (UTC)
 * I have rewritten the section. Now the text is here. Ftiercel (discuss • contribs) 19:00, 1 February 2013 (UTC)

Errors
There are various amounts of errors on this page compared to the previous ones. Consider getting it revised.


 * Such as? 81.187.215.34 (discuss) 16:57, 2 July 2016 (UTC)

Parameter Passing
The section was changed to "The object references are passed by value." (which finally seems to be the consensus) but now other parts of the page make no sense:
 * Objects can't be parameters only references can be.
 * The introductory text "We can pass any primitive data types or objects to a method but the two are not processed the same way." doesn't fit.
 * The headings of the code examples "Parameter by reference." are not right.
 * The subsections may need changing. 81.187.215.34 (discuss) 17:08, 2 July 2016 (UTC)

Missing term
"[visibility] [return type] [name] [input parameters]" such as "private int methodName(String parameter1, String parameter2)" is called the "method signature". In the page I see something called the "method definition"; it is unclear to me what that is.User000name (discuss • contribs) 15:04, 2 March 2017 (UTC)