• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

calling a method

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

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.
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
{
Class2()
{
Class1 c1 = new Class1();
c1.myMethod2();
}

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

class Class1 extends Class2
{
Class2()
{
myMethod1();
}

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...
reply
    Bookmark Topic Watch Topic
  • New Topic