my dog learned polymorphism
The moose likes Beginning Java and the fly likes calling a method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "calling a method" Watch "calling a method" New topic

calling a method

renu yella

Joined: Aug 25, 2004
Posts: 1

I am new to Java.Trying to learn myself. I have created 2 different classes (let me say class1 and class2)from which one class in inherited.I have created an object , set and get methods(like settotal(),getcode()) in class1. I inherited class in class2 . in class to i have given few other set and get methods. I even wrote toString method in class2 to call all the methods. I am able to call the methods only from class2 but not from class1. it is showing an error as cannot resolve symbol method getcode();

I wonder how to call the methods from class1 to class2. My main class is again a different class.

plz help me out.
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
Welcome to JavaRanch, renu!

Could you post some example code that creates the error message you're getting?

When posting code, please be sure to surround the code with the [code] and [/code] UBB Tags. This will help to preserve the formatting of the code, thus making it easier to read and understand.

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Shashank Agarwal
Ranch Hand

Joined: May 20, 2004
Posts: 105
Well, you are not able to call class1 from class2 because class1 has inherited class2's methods, but class1 has'nt. do this -

lets assume Class1 is extending Class2

public class Class2
Class1 c1 = new Class1();

public void myMethod1()
System.out.println("My Method 1 Called");

class Class1 extends Class2

public void myMethod2()
System.out.println("My Method 2 called");

Understood how class1 can now call methods in class2 and class2 in class1? I hope u did...
I agree. Here's the link:
subject: calling a method
It's not a secret anymore!