Hi team,
Can any one say what is instance Method in java ?
*Method Overriding Concept?

Thank you,


with Regards,
Prem

Edited 6 Years Ago by prem2: n/a

Instance method - method defined in a class which is only accessable through the Object of the class are called Instance method.

Method Overriding - If you extends a class and have a method in the subclass with same name and signature as of the superclass, then it is called method overriding.

Example of method overriding -

class superClass {
    public void display(String str) {
        System.out.println("Superclass : "+str);
    }   
}

class subClass extends superClass {
    public void display(String str) {
        System.out.println("Subclass : "+str);
    }   
}

Also the display() method is instance method as you can't invoke them without instance of the class.

Hi team,
Can any one say what is instance Method in java ?
*Method Overriding Concept?

Thank you,


with Regards,
Prem

Hi team,
Can any one say what is instance Method in java with example?

Thank you,


with Regards,
Prem

An instance method is a method of an instantiated class.
A simple example might be this: You have a Class representing Cat. Each Cat can do some things - it can meow, purr, catch mice, and so forth. Each of those things is the same action no matter which cat does it, so the method is method of the class Cat. But each particular meowing, purring, or catching of mice is done by one particular cat, so it's an instance method.

Cat fluffy = new Cat("Fluffy");
Cat spooky = new Cat("Spooky");
Cat mongo = new Cat("Mongo");

fluffy.meow();
spooky.purr();
mongo.sleep();

The methods you write are instance methods unless you declare them "static". Static methods pertain to the class as a whole. For your Cat class, you might have a method like "preferredFood()" which would return the string "tuna", since as we know all cats prefer tuna to all other foods. If we discover that cats actually prefer filet mignon to tuna, you could change preferredFood() so that it returns "filet mignon", and it would now return "filet mignon" for all cats.

When a method declaration includes a static modifier, that method is said to be a static method. When no static modifier is present, the method is said to be an instance method.

help ful links

http://msdn.microsoft.com/en-us/library/aa645766%28v=vs.71%29.aspx
http://www.geom.uiuc.edu/~daeron/docs/javaguide/java/anatomy/static.html

Comments
Come on, the post is two years old. And why are you referencing a C# article? Yeah, they're similar, but it constantly references other parts of the C# specification (which tends to be quite different).

@methakon
Your contributions to DaniWeb are very welcome, but please check the dates before responding to an old thread. @prem2 had his answer 2 years ago, so your answer is (1) not needed and (2) 2 years too late.
Your first "helpful" link is for C#, not Java.

This article has been dead for over six months. Start a new discussion instead.