creating instance of parent class ?

Discussion in 'Java' started by mhk, Nov 29, 2003.

  1. mhk

    mhk Guest

    Hi ,

    i cannot create instance of parent class ( test1.java ) in my derived
    class (test2.java ) while using package.

    if i dont use package then it prints "value = 3" but i want it to work
    with package. The error is that "test2.java" doesn't know about
    "test1.java" while using package.

    can anyone help in solving this problem.

    Thanks and here is the sample code below.



    test1 class "test1.java" is
    ---------------------
    package search;

    public class test1
    {
    public test1() {}

    public int val1()
    {
    return(3);
    }
    }

    AND MY 2nd class is "test2.java"
    -----------------------------------
    package search;

    public class test2 extends test1
    {
    public test2() {}
    public static void main(String[] args)
    {
    test1 t = new test1();
    System.out.println ("value = "+ t.val1() );
    }
    }

    ***************************************
    mhk, Nov 29, 2003
    #1
    1. Advertising

  2. mhk

    Chris Smith Guest

    mhk wrote:
    > Hi ,
    >
    > i cannot create instance of parent class ( test1.java ) in my derived
    > class (test2.java ) while using package.
    >
    > if i dont use package then it prints "value = 3" but i want it to work
    > with package. The error is that "test2.java" doesn't know about
    > "test1.java" while using package.
    >
    > can anyone help in solving this problem.


    I can ask for more information. The code you've posted is fine, so to
    answer your question, I'd need to know:

    1. Presumably this is a compiler error. What's the error message?

    2. From what directory are you running the compiler?

    3. What is the exact command line you use to compile?

    4. What is the value, if any, of your CLASSPATH environment variable?

    --
    www.designacourse.com
    The Easiest Way to Train Anyone... Anywhere.

    Chris Smith - Lead Software Developer/Technical Trainer
    MindIQ Corporation
    Chris Smith, Dec 2, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sridhar R
    Replies:
    14
    Views:
    1,400
    =?iso-8859-1?Q?Fran=E7ois?= Pinard
    Feb 10, 2004
  2. gentlestone
    Replies:
    6
    Views:
    943
    Bruno Desthuilliers
    Oct 6, 2009
  3. metal
    Replies:
    8
    Views:
    503
    Bruno Desthuilliers
    Oct 30, 2009
  4. Martin P. Hellwig
    Replies:
    1
    Views:
    374
    Martin P. Hellwig
    Mar 26, 2010
  5. Olive
    Replies:
    4
    Views:
    242
    Olive
    Jul 6, 2012
Loading...

Share This Page