• 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
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

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: 13091
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.
 
Just the other day, I was thinking ... about this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic