creating instance of parent class ?

M

mhk

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() );
}
}

***************************************
 
C

Chris Smith

mhk said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top