File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

not wanted methods getting invoked when created an object

 
Ransika deSilva
Ranch Hand
Posts: 524
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello world,
I am writting a program which has a structure like this.
public class x
{
public x()
{
}
}
class a
{
public a()
{
}
public void methodA()
{
}
}
class b
{
public b()
{
}
public void methodB()
{
}
}
The problem I am having is, if I create an object of, for example 'class b' and access the
methodB() from 'class a', not only the methodB() gets invoked but also other methods which
are there in the 'class b' gets invoked. Could you please explain what is wrong and how to
over come this. All the methods are public in the program.
Thanks
 
Kim Kantola
Ranch Hand
Posts: 276
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Are you making an object of class b from within class x? Is a method from class b being called from within the constructor or another method of class a? Class b has another method besides methodB which is being called?
For example, is your code something like this?:
public class x
{
public x()
{
a object_of_a = new a();
}
}
class a
{
public a()
{
b object_of_b = new b();
b.methodB();
}
public void methodA()
{
}
}
class b
{
public b()
{
}
public void methodB()
{
}
}
 
Jeff Bosch
Ranch Hand
Posts: 805
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Ransika and Kim -
When posting code, would you please use the UBB CODE tags and also indent code lines? The UBB codes format the code and make it much easier to read, as does indentation.
Cheers!
Jeff
 
Kim Kantola
Ranch Hand
Posts: 276
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just trying out the ubb code to see how it works, haven't used it before.
Thanks for the suggestion.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BTW, you can also edit your old posts (and delete the once that become superfluous by doing so - just be aware of the fact that deleting the first in a thread deletes the whole thread...).
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And just to point out the obvious, I think Kim meant to post a code example as follows.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic