Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

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
reply
    Bookmark Topic Watch Topic
  • New Topic