Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Hi , need clarification on how to get the object from one class to another class

  1. #1
    Junior Member
    Join Date
    Nov 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Hi , need clarification on how to get the object from one class to another class

    Hi iam a new user,

    Right now im working in selenium and i have knowledge on java basic programming and little bit
    about oops.Here is my question

    1. I have a class "SeleniumCore" , from class B i have inherited the object and the actions are successfully performed.

    2. My folder structure is like

    SeleniumCore - >ClassB (Action performed) ->Class C ->Class D

    From class D i want to invoke the SeleniumCore object.
    when i invoke and run at class D the object shows the null value and which means that not able to take the
    initial object value.

    Kindly help me to understand the oops concept here

    Thanks,
    Sha


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Hi , need clarification on how to get the object from one class to another class

    An object can be passed to another class through a constructor of the second class:

    ClassA classA = new ClassA();
    ClassB classB = new ClassB( classA );

    classB has the object classA to do with as it pleases.

    Another way is to use setters:

    ClassA classA = new ClassA();
    ClassB classB = new ClassB();
    classB.setClassA( classA );

    Hope this helps.

  3. #3
    Junior Member
    Join Date
    Nov 2013
    Posts
    4
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Hi , need clarification on how to get the object from one class to another class

    In ClassD you can created object of SeleniumCore class's object. In following code I have created object of class SeleniumCore in class ClassD and printed it ,

Similar Threads

  1. Replies: 2
    Last Post: October 9th, 2013, 08:36 AM
  2. Replies: 149
    Last Post: February 19th, 2013, 10:04 PM
  3. Replies: 1
    Last Post: February 14th, 2013, 07:30 PM
  4. Can't create inner class object outside the outer class help needed?
    By Dark knight in forum Java Theory & Questions
    Replies: 2
    Last Post: July 31st, 2012, 02:34 AM
  5. Convert File Object to class<?> object
    By CEO in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: June 27th, 2012, 06:55 PM