Hello,

you should create proper parent class and establish hierarchy where
child class will extend its parent something like that:

public class Example1 {
    private String ex;

    public Example1( ) {
    }

    public Example1( String ex) {
        this.ex = ex;
    }

    public String getEx() {
        return ex;
    };

public class ExChild extends Example1 {
    public ExChild(String ex) {
        super(ex);
    }
Next in main instantiate both parent and child objects and call proper
methods for parent and child:

public static void main(String[] arg)
        {
                Example1 parent = new Example1("hello world from
parent");

            Example1 child = new ExChild("hello from child");


         System.out.println("Parent: " + parent.getClass() + ", " +
                 parent.getEx());

         System.out.println("Child: " + child.getClass() + ", " +
                 child.getEx());
        }


Regards,
Moria.
-----Original Message-----
From: java-ee-j2ee-programming-with-passion@googlegroups.com
[mailto:java-ee-j2ee-programming-with-pass...@googlegroups.com] On
Behalf Of tedpottel
Sent: Wednesday, September 23, 2009 9:45 AM
To: Java EE (J2EE) Programming with Passion!
Subject: [java ee programming] Trying to get a child calss to call a
function in its parent class


Hi,
Can I get this to work,

package pacTestLib;

public class clTestLib {
        public static void main(String[] arg)
        {
                System.out.println("hello world");
                testLibClass cl = new testLibClass(this);
                cl.test();
        }
        public CallPar()
        {
                System.out.println("hello from parent");
        }

}

I'm trying to find out a way for a child to access its parent,
Ted



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Java EE (J2EE) Programming with Passion!" group.
To post to this group, send email to
java-ee-j2ee-programming-with-passion@googlegroups.com
To unsubscribe from this group, send email to
java-ee-j2ee-programming-with-passion+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/java-ee-j2ee-programming-with-passion?hl=en?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to