• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

What does this mean?

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"A file can have more than one nonpublic class."
 
Ranch Hand
Posts: 959
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It means you can have something like this (more than one non-public class in a file and only a single public class in a file).
MyApp1.java


but it's illegal to have something like this (more than one public class in a file).
MyApp2.java


Hope this helps
 
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Small correction to above post:
 
Freddy Wong
Ranch Hand
Posts: 959
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yup, my mistake. Forgot about the file name
 
Xyz Abc
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks guys, that cleared my doubt
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So does the interface!!
 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Wentao Liang,
Even in the interface also, we can not place one more public class.
It gives error like " The public type of subclass must be in its own file ". Just check this code.


public interface InterfaceTesting {
void display();


}
public class SubClassOfInterface implements InterfaceTesting{
public void display(){
System.out.println("in display Method");
}

public static void main(String args[]){
SubClassOfInterface subClass = new SubClassOfInterface();
subClass.display();

}
}


the above code give error..



package com;

public interface InterfaceTesting {
void display();


}
class SubClassOfInterface implements InterfaceTesting{
public void display(){
System.out.println("in display Method");
}

public static void main(String args[]){
SubClassOfInterface subClass = new SubClassOfInterface();
subClass.display();

}
}

will give output as ...
in display Method


reply me if i am mistake ....


Suneel.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic