• 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

Please help me

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello ~
----------------------------------------------------------------------------Code:
package test1;
public class Test1{
static int x=42;
}

package test2;
public class Test2 extends test1.Test1{
public static void main(String[] args){
System.out.println("X=n"+x);
}
}
Why it compilation fails?
Thanks
 
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Hu Peng:
Hello ~
----------------------------------------------------------------------------Code:
package test1;
public class Test1{
static int x=42;
}

package test2;
public class Test2 extends test1.Test1{
public static void main(String[] args){
System.out.println("X=n"+x);
}
}
Why it compilation fails?
Thanks





x has got default access which means that its invisible outside its own package..But if you change access modifier to protected,it will work[It gets access through inheritence]..

HTH
Prashanth
 
Hu Peng
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you!
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just a gentle note... it would help in the future if you also posted the exact compilation error message. for something as small as this, it might not matter much, as it's fairly easy to see. But the bigger your code gets, the more important it becomes.

those error messages often give a pretty big clue as to what the problem is, so it's a good idea to start learning what they mean.
 
I claim this furniture in the name of The Ottoman Empire! You can keep this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic