Lesson 23
Lesson 23
COMPUTER APPLICATIONS
CLASS – X
Instance Method
Instance method are methods which require an object of its class to be created
before it can be called. To invoke an instance method, we have to create an
Object of the class in within which it defined.
Page 1
COMPUTER APPLICATIONS Class X
TOPIC :- Methods( Lesson 23)
Also static methods exist as a single copy for a class while instance methods
exist as multiple copies depending on the number of instances created for that
particular class.
Instance method can access the instance methods and instance variables
directly. Instance method can access static variables and static methods directly.
Static methods can access the static variables and static methods directly. Static
methods can’t access instance methods and instance variables directly. They
must use reference to object. And static method can’t use this keyword as there
is no instance for ‘this’ to refer to.
this keyword :
Keyword 'this' in Java is a reference variable that refers to the current object.
"this" is a reference to the current object, whose method is being called upon.
You can use "this" keyword to avoid naming conflicts in the
method/constructor of your instance/object.
Page 2
COMPUTER APPLICATIONS Class X
TOPIC :- Methods( Lesson 23)
Page 3
COMPUTER APPLICATIONS Class X
TOPIC :- Methods( Lesson 23)
Example:
class Account{
int a;
int b;
Page 4