|
-
Feb 25th, 2006, 09:51 AM
#1
Thread Starter
Lively Member
Why is this happening?
Hi. I am having this problem. I know the solution but i want to know why the problem happened?
i have this:
if (obj.getClass() == Student.getClass())
Student temp = (Student)obj;
I get a compilation error, non-static methode getClass() cannot be referenced from a static context.
i am using this code instead of: if (obj instenceof Student)
When i use: if (obj.getClass() == getClass()) i don't have a problem.
So can anyone please explain what the error means? Why is it saying i am calling from a static context. the method this code is in is not static. i am calling it from the equals method in the Student class.
thanks.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|