• 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

Marcus Green - Question 8

 
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everybody
Question 8)
What will happen when you attempt to compile and run this code?
private class Base{}
public class Vis{
transient int iVal;
public static void main(String elephant[]){
}
}
1)Compile time error: Base cannot be private
2)Compile time error indicating that an integer cannot be transient
3)Compile time error transient not a data type
4)Compile time error malformed main method
Answer 8)
Objective 1.2)
1)Compile time error: Base cannot be private
A top leve (non nested) class cannot be private.

Can anybody help me to understand this clearly ? I was thinking that private class Base{} is a standalone entity in that code.
Thanks
ARS Kumar
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Kumar,
JLS says that only an inner classes can be declared as private, protected or static. Any top-level class (which not nested) can only be declared as public or friendly (with no modifier). Compile time error will be encountered if a top level class is marked as private.
Hope this helps !!
Regards,
Milind

[This message has been edited by Milind (edited May 29, 2000).]
[This message has been edited by Milind (edited May 29, 2000).]
 
ARS Kumar
Ranch Hand
Posts: 108
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Milind,
Thanks for your help.
ARS Kumar
 
I didn't do it. You can't prove it. Nobody saw me. The sheep are lying! This tiny ad is my witness!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic