Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Challenging tasks GUY ,Please Help Me

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic