package class


import java.io.*;
import java.lang.*;
import java.util.*;


package Yo

public class C 
{
       String s,f,d;


     C(String s,String f,String d)
      {
        this.f=f;
        this.s=s;
        this.d=d;

      }
      void displayj()
      {
       System.out.println("1st arg passed:"+"  "+s);
        System.out.println("2nd arg passed:"+"  "+f);
        System.out.println("single arg const:"+"  "+d);
       }


}




main class

import java.lang.*;
import java.io.*;
import java.util.*;
import java.Yo.*;


class B extends C
{

            String s,d,h,f;
   B(String h,String s,String f,String d)
     {
        super(s,f,d);

         this.h=h;

     }

    void display()
     {
        System.out.println("b class const:"+"  "+h);
         displayj();
      }

}

class A1 
{  

  public static void main(String args[])throws IOException
   {

     Scanner s=new Scanner(System.in);


      B anu=new B(s.nextLine(),"haiii","i rock","punk");

        anu.display();


   }
}

i created a folder in D:\ and stored the package class in it
den gave its path in environmental variable
and executed the main class
i still get error that package not found

Recommended Answers

All 7 Replies

that's normal.
first of all, your package statement has to be the very first one in your java file, so before your import statements.

secondly, you haven't named your package java.Yo, you named it Yo, so, change your code to:

package Yo; // don't forget the ;
import java.io.*;
import java.lang.*;
import java.util.*;
...

and your other class:

import java.lang.*;
import java.io.*;
import java.util.*;
import Yo.*; /* there is no java. , this is only in packages which actually start in a java folder */


class B extends C
{
...

There are two things
package name should always end with semicolon.
secondly,package declaration should always be the first statement of your code.

i still get an error that C(java.lang.String) is not public and can not be accessed outside package

error at super(s,f,d);

Declare constructor C as public.

make it
public C(

Please mark it as solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.