This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin for Android App Development and have Peter Sommerhoff on-line!
See this thread for details.
Win a copy of Kotlin for Android App Development this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Accessing a class from within the package  RSS feed

 
Ranch Hand
Posts: 145
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wrote this code

//PublicBeverageInSamePack.java
package cert;

public class PublicBeverageInSamePack {

void show(){
System.out.println("Beverage in the same pack");
}

}

//TeaInSamePackPublic.java

package cert;

import cert.PublicBeverageInSamePack;

class TeaInSamePackPublic extends PublicBeverageInSamePack {
public static void main(String args[]) {
PublicBeverageInSamePack ob = new PublicBeverageInSamePack();
ob.show();
}

}

When i compiled this program, it gave me the following compile time error.

E:\NancyWork\SunCertification\scjp6\KB\chapter1\cert\TeaInSamePackPublic.java:3: cannot find symbol
symbol : class PublicBeverageInSamePack
location: package cert
import cert.PublicBeverageInSamePack;
^
E:\NancyWork\SunCertification\scjp6\KB\chapter1\cert\TeaInSamePackPublic.java:5: cannot find symbol
symbol: class PublicBeverageInSamePack
class TeaInSamePackPublic extends PublicBeverageInSamePack {
^
E:\NancyWork\SunCertification\scjp6\KB\chapter1\cert\TeaInSamePackPublic.java:7: cannot find symbol
symbol : class PublicBeverageInSamePack
location: class cert.TeaInSamePackPublic
PublicBeverageInSamePack ob = new PublicBeverageInSamePack();
^
E:\NancyWork\SunCertification\scjp6\KB\chapter1\cert\TeaInSamePackPublic.java:7: cannot find symbol
symbol : class PublicBeverageInSamePack
location: class cert.TeaInSamePackPublic
PublicBeverageInSamePack ob = new PublicBeverageInSamePack();
^
4 errors

Process completed with exit code 1

When the same class is shifted to another package it works. Does it mean that class in the same package cannot be imported.
 
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you compiled it properly?
check whether the PublicBeverageInSamePack.class was in cert package or not?
 
Sheriff
Posts: 9643
42
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since both TeaInSamePackPublic and PublicBeverageInSamePack classes are in the same package, you don't need to use import...
 
I'm not sure if I approve of this interruption. But this tiny ad checks out:
Programmatically Create PDF Using Free Spire.PDF with Java
https://coderanch.com/wiki/703735/Programmatically-Create-PDF-Free-Spire
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!