Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Challenging tasks GUY ,Please Help Me  RSS feed

 
narayana murthy pedapudi
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a Main Class and from there i am calling another class by creating an object.
like this
Class MainClass
{
SubClass subObj = new SubClass();
MainClass()
{}
public static void main(String args[])
{
new MainClass();

}
}
Now the problem is i have to access some components of the MainClass without
Creating an object of the MainClass remember that i don't even want to do Extend the MainClass to SubClass(This is for some other reson).
if atall i create an Object of MainClass in the SubClass then it will create another Object ...
think that i want to add a table to the panel in the main class...
and later i want to remove it from the SubClass then it is will simply give
NullPointerException....
Please let me know ur solutions on this...

Summary:
I want to access the back class object without creating a new Object for that, it means i want to access the back class object the same object which is pointed by the backclass....
Please resolve this
bye
naryana
 
Mahesh swami
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What If you pass the reference of Object of main class to the constructor of subclass object like this
MainClass(){
Subclass sub = new SubClass(this);
}
-Mahesh
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!