I was writing a program with Packages.
Created a directory called P1 and wrote these programs
1)Protection.java
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);
}
}
2)Derived.java
package p1;
class Derived extends Protection
{
Derived()
{
System.out.println("Derived 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);
}
}
3)SamePackage.java
package p1;
class SamePackage
{
samePackage()
{
Protection p = new Protection();
System.out.println("Same Package
Constructor");
System.out.println("n"+p.n);
//System.out.println("n_pri"+p.n_pri);
System.out.println("n_pro"+p.n_pro);
System.out.println("n_pub"+p.n_pub);
}
}
4)Demo.java
package p1;
public class Demo
{
public static void main(String args[])
{
Protection ob1 = new Protection();
Derived ob2 = new Derived();
SamePackage ob3 = new SamePackage();
}
}
But iam not able to compile it . These are the error messages on
compiling
C:\j2sdk1.4.1_03\bin\p1>javac Demo.java
Demo.java:7: cannot resolve symbol
symbol : class Protection
location: class p1.Demo
Protection ob1 = new Protection();
^
Demo.java:7: cannot resolve symbol
symbol : class Protection
location: class p1.Demo
Protection ob1 = new Protection();
^
Demo.java:8: cannot resolve symbol
symbol : class Derived
location: class p1.Demo
Derived ob2 = new Derived();
^
Demo.java:8: cannot resolve symbol
symbol : class Derived
location: class p1.Demo
Derived ob2 = new Derived();
^
Demo.java:9: cannot resolve symbol
symbol : class SamePackage
location: class p1.Demo
SamePackage ob3 = new SamePackage();
^
Demo.java:9: cannot resolve symbol
symbol : class SamePackage
location: class p1.Demo
SamePackage ob3 = new SamePackage();
^
6 errors