Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2007

Tip: Looking for answers? Try searching our database.

Same Method name

Thread view: 
durgaapparaobsc@gmail.com - 14 Mar 2007 07:37 GMT
Hai.......users.....

This is appu........

i learning to the java ........i want to a small dought

can we create same name of static method and instance method

with the same class

with regards

appu
ck - 14 Mar 2007 07:58 GMT
On Mar 14, 11:37 am, durgaapparao...@gmail.com wrote:
> Hai.......users.....
>
[quoted text clipped - 9 lines]
>
> appu

Yes
--
Ck
http://www.gfour.net
durgaapparaobsc@gmail.com - 14 Mar 2007 08:08 GMT
hello sir,

this is appu....

if dont mind write that code else i write to here any modification to
correct the stuff

class SameName {

//Constroctor
SameName() {
this.dis();
}

//instance method
void dis() {
S.o.p("This is Instance method");
}

static void dis() {
S.o.p("This is Static method");
}

class Demo {
public static void main(String a[]) {
SameName sn = new SameName();
sn.dis();
SameName.dis();
}
}

In the above stuff comes to the error plz send the mail to with
modifications..........

with regards
Appu
ck - 14 Mar 2007 09:05 GMT
On Mar 14, 12:08 pm, durgaapparao...@gmail.com wrote:
> hello sir,
>
[quoted text clipped - 36 lines]
> with regards
> Appu

method name can be same but method signature have to be different to
coexist.

Change one of the dis by adding parameter to it.
Eg:-
void dis() {
// do something
}

static void dis(String parm){
// do something else
}

--
Ck
http://www.gfour.net
Lew - 14 Mar 2007 14:30 GMT
durgaapparao...@gmail.com wrote:
>> hello sir,
>> class SameName {
[quoted text clipped - 8 lines]
>> void dis() {
>> S.o.p("This is Instance method");

What is 'S.o.p'? I see no definition.

Please provide SSCCEs.

>> }
>>
>> static void dis() {
>> S.o.p("This is Static method");

Consider indenting code by a few spaces as suggested by the Sun Java coding
conventions (Sun, 1999) and nearly universally practiced.

>> }
>>
[quoted text clipped - 6 lines]
>> }
>> }

ck answered your main question. The compiler resolves method signatures first,
'static' and other qualifiers after. Two methods with the same name in the
same class must have different signatures (overloading).

-- Lew
Tor Iver Wilhelmsen - 22 Mar 2007 19:28 GMT
På Wed, 14 Mar 2007 07:37:27 +0100, skrev <durgaapparaobsc@gmail.com>:

> can we create same name of static method and instance method

Methods have to be different in their signatures; the signature is made up  
of the case-sensitive name and the parameter types, in order. Since  
neither return type or modifiers like static form part of the signature,  
you cannot have a static and a non-static method with the same name and  
parameter list, nor two methods with the same name and parameter list that  
returns different things.
Mike Schilling - 23 Mar 2007 04:26 GMT
> På Wed, 14 Mar 2007 07:37:27 +0100, skrev <durgaapparaobsc@gmail.com>:
>
[quoted text clipped - 6 lines]
> same name and parameter list, nor two methods with the same name and
> parameter list that returns different things.

Nor, I think, methods that differ only in whether (or how) an argument is
genericized, e.g. not both

   void method(List l)

and

   void method(List<T> l).


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.