wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes instance varibles and static methods???? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "instance varibles and static methods????" Watch "instance varibles and static methods????" New topic
Author

instance varibles and static methods????

Amit Das
Ranch Hand

Joined: Mar 05, 2005
Posts: 206
hi all,

plz refer this code:


Ques. Why does call to instance vaiable i on object ref of super class, but instance of sub class, give the o/p 0??? how this happens?? is this decided at compile time??? I know variables are not called polymorphically, but why this is so???
At the same time call to the static method is also not polymorphic but that is understood.

thanx
amit
Rohan Kayan
Ranch Hand

Joined: Sep 17, 2004
Posts: 123
The instance variables and static members are decided at compile time , only instance methods are decided at runtime , that is why the output is so .


SCWCD 1.4, SCJP 1.4
Amit Das
Ranch Hand

Joined: Mar 05, 2005
Posts: 206
hi Rohan,

ur answer is just a reinvention of the wheel...........
i intended on asking why its so(why such behavoir has been made to exhibit)??

thanx
amit
Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026
JLS

15.28 Constant Expression
ConstantExpression:
Expression
A compile-time constant expression is an expression denoting a value of
primitive type or a String that is composed using only the following:

� Literals of primitive type and literals of type String


Since the member variable i in class Amit is a compile time constant it is resolved at compile time.


Servlet Spec 2.4/ Jsp Spec 2.0/ JSTL Spec 1.1 - JSTL Tag Documentation
Pooja Shankar
Greenhorn

Joined: Mar 29, 2005
Posts: 16
the static method is not actually overridden, as you expect it to be.remove the static modifier and you'll see the result after overridding takes place.
Pooja Shankar
Greenhorn

Joined: Mar 29, 2005
Posts: 16
the static method is not actually overridden, as you expect it to be.remove the static modifier and you'll see the result after overridding takes place.
 
Consider Paul's rocket mass heater.
 
subject: instance varibles and static methods????
 
Similar Threads
Output Doubt
Is it possible to invoke a method before even the object gets created?
order?
need help
Help in statics