Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

question regarding package and import..

Ranch Hand
Posts: 176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have two classes , one of them It is in usr/users/rbg01/java/reddy
and the other is in usr/users/rbg01/java/reddy/test
how should be my package and import names, when i try to compile it says it can't find the
i have tried giving different paths for import and package statements but it didn't work.,
can some one throw light on this..
Posts: 3341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This could be starting with you class path. It needs to have ./ in it to indicate the current directory. Then your source code needs to be placed in the same directory /java.
Remember each directory is actually a different package so anything you wish to share out side the package Constrictors, Methods etc must have public or protected access modifier
After you compile each, copy the class file to the currect subdirectory. Example:
package reddy;
public class Parent1{
public Parent1()
System.out.println("Parent Hello");
package reddy.test;
import reddy.Parent1;
public class child extends Parent1{
public child()
System.out.println("child Hello");

import reddy.*;
import reddy.test.child;
public class run{
public static void main(String args[])
child c = new child();
typeing java run gives the following output
Parent Hello
child Hello
Don't get me started about those stupid light bulbs.
    Bookmark Topic Watch Topic
  • New Topic