• 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 ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

public class inside a package

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello,
Why cnnot i have a public class or public static void main
inside a package why does it give error.
The code below is for reference.
package hello;

class pack1 {
void show()
{
System.out.println("Hello pack1");
}
}

class subpack1 extends pack1 {
void show()
{
System.out.println("Hello subpack1");
}
}

class diffpack {
void show()
{

System.out.println("Hello pack1");
}
}
class xyz {
public static void main(String args[])
{
pack1 a = new subpack1();
a.show();
diffpack b = new diffpack();
b.show();
}
}

- thanks in Advance

regards
- mohan
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't see any problem. in your hello directory you compile your file xyz.java. Then you go up one level of the directory
(cd ..) and run your program by "java hello.xyz"
cheers
 
Being a smart alec beats the alternative. This tiny ad knows what I'm talking about:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic