• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Packages

 
jack worthing
Greenhorn
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 602
7
Mac OS X Python
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
-- 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
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 202
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
jack worthing
Greenhorn
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please use code tags when you post source code.
 
Henry Wong
author
Marshal
Pie
Posts: 20836
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Steve Fahlbusch
Bartender
Posts: 602
7
Mac OS X Python
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What i had thought - and Henry beat me back here - do what Henry says and you should be fine.


-steve
 
jack worthing
Greenhorn
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thankyou Henry
It worked .
 
jack worthing
Greenhorn
Posts: 18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thankyou friends
thanks for your concern.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic