Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > creating instance of parent class ?

Reply
Thread Tools

creating instance of parent class ?

 
 
mhk
Guest
Posts: n/a
 
      11-29-2003
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() );
}
}

***************************************

 
Reply With Quote
 
 
 
 
Chris Smith
Guest
Posts: n/a
 
      12-02-2003
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating an instance when the argument is already an instance. Olive Python 4 07-06-2012 02:01 PM
Don't understand behavior; instance form a class in another class'instance Martin P. Hellwig Python 1 03-26-2010 12:06 AM
If a class Child inherits from Parent, how to implementChild.some_method if Parent.some_method() returns Parent instance ? metal Python 8 10-30-2009 10:31 AM
converting base class instance to derived class instance Sridhar R Python 14 02-10-2004 02:47 PM
Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class. DJ Dev ASP .Net 3 02-08-2004 04:19 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57