954,549 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

package in java

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

mallikaalokam
Newbie Poster
23 posts since Feb 2012
Reputation Points: 10
Solved Threads: 1
 

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
{
...
stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
 

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

rushikesh jadha
Junior Poster in Training
89 posts since Dec 2011
Reputation Points: 4
Solved Threads: 11
 

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);

mallikaalokam
Newbie Poster
23 posts since Feb 2012
Reputation Points: 10
Solved Threads: 1
 

Declare constructor C as public.

rushikesh jadha
Junior Poster in Training
89 posts since Dec 2011
Reputation Points: 4
Solved Threads: 11
 

make it
public C(

stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
 

yup got it
arigato:)

mallikaalokam
Newbie Poster
23 posts since Feb 2012
Reputation Points: 10
Solved Threads: 1
 

Please mark it as solved.

rushikesh jadha
Junior Poster in Training
89 posts since Dec 2011
Reputation Points: 4
Solved Threads: 11
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: