aspose file tools*
The moose likes Beginning Java and the fly likes Packages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Packages" Watch "Packages" New topic
Author

Packages

jack worthing
Greenhorn

Joined: Dec 02, 2008
Posts: 18
Hi,
can any body help me in this.
The class Protection compiles but the classes Derived,SamePackage and Demo dont' on my dos promt,where all the files are in the same folder.
But all are fine on the Eclipse tool,for which I use a different directory and copied the same files to there,they all are compiled and executed.
Cant understand why they dont' compile on dos.

package p1;

public class Protection{

int n=1;
private int n_pri=2;
protected int n_pro=3;
public int n_pub=4;

public Protection(){
System.out.println("base constructor");
System.out.println("n = " + n);
System.out.println("n_pri = " + n_pri);
System.out.println("n_pro = " + n_pro);
System.out.println("n_pub = " + n_pub);
}
public static void main(String[] args){
System.out.println("In Baseclass--->Protection");
}
}

package p1;

class Derived extends p1.Protection{
//Derived(){
//System.out.println("derived constructor");
//System.out.println("n = " + n);
//System.out.println("n_pro = " + n_pro);
//System.out.println("n_pub = " + n_pub);
//}
public static void main(String[] args){
System.out.println("In Subclass--->Derived");
}
}

package p1;

class SamePackage{
SamePackage(){
Protection p=new Protection();
System.out.println("same package constructor");
System.out.println("n = " + p.n);
// class only
// System.out.println("n_pri = " + p.n_pri);
System.out.println("n_pro = " + p.n_pro);
System.out.println("n_pub = " + p.n_pub);
}
}

//package p1;
import Mypackage.Edocs;
public class Demo {
public static void main(String args[]){
//Protection ob1 = new Protection();
//Derived ob2 = new Derived();
///SamePackage ob3 = new SamePackage();
}
}


Thankyou for your concern.
Steve Fahlbusch
Bartender

Joined: Sep 18, 2000
Posts: 571
    
    7

-- you have run into one of the many reasons the folks around here suggest always starting with a simple editor not an IDE - as the IDE does things behind your back --

But to your issue:

please answer the following questions:

1) what is the full path name of the directory of where you placed the source files?

2) what is the full path name of where you attempted to compile said sources files?

3) what is the exact command you issued to compile the source files in 1 while in directory 2?

4) what (if any) message did you get?

-steve
jack worthing
Greenhorn

Joined: Dec 02, 2008
Posts: 18
sorry,
the Demo class was like this.


package p1;
public class Demo {
public static void main(String args[]){
Protection ob1 = new Protection();
Derived ob2 = new Derived();
SamePackage ob3 = new SamePackage();
}
}
camilo lopes
Ranch Hand

Joined: Aug 08, 2007
Posts: 202
other point very important. It isn`t necessary you use


when the class is on same folder it is not necessary you do it.

I recommend you use a IDE to development is better.

tks


Brazil - Sun Certified Java Programmer - SCJP 5
http://www.camilolopes.com/ About Java - Update every Week.
Guide SCJP - tips that you need know http://blog.camilolopes.com.br/livrosrevistaspalestras/
jack worthing
Greenhorn

Joined: Dec 02, 2008
Posts: 18
they all are in this directory
C:\VAS1\p1
Folder p1 holds all the .java files.
The command I used was C:\VAS1\p1\javac Derived.java
The error was
cannot find symbol
symbol : class Protection
location: package p1
class Derived extends p1.Protection{
^

Thankyou
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14272
    
  21

Please use code tags when you post source code.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40

Originally posted by jack worthing:
they all are in this directory
C:\VAS1\p1
Folder p1 holds all the .java files.
The command I used was C:\VAS1\p1\javac Derived.java


You have to compile it from the right location. Try (assuming your classpath is not set, or set correctly) ...

cd c:\VAS1
javac p1\Protection.java
javac p1\Derived.java

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Steve Fahlbusch
Bartender

Joined: Sep 18, 2000
Posts: 571
    
    7

What i had thought - and Henry beat me back here - do what Henry says and you should be fine.


-steve
jack worthing
Greenhorn

Joined: Dec 02, 2008
Posts: 18
thankyou Henry
It worked .
jack worthing
Greenhorn

Joined: Dec 02, 2008
Posts: 18
thankyou friends
thanks for your concern.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Packages