• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Compiler errors at line 7, 15 & 13

 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

The compiler throws me error messages at line 7, 15 & 13 for the following code. I find it hard to understand compiler's English. So I will type them out here for the experts.

line 07 error: mySuperClass(int) in mySuperClass cannot be applied to () class mySubClass extends mySuperClass.

line 15 error: non-static variable this cannot be referenced from a static context.

line 13 error: inner classes cannot have static declarations public static void main (String args[])

Here's the code. How should the 3 lines be re-written in order to work?:

line 01: class mySuperClass
line 02: {
line 03: mySuperClass(int i)
line 04: {
line 05: }
line 06:
line 07: class mySubClass extends mySuperClass
line 08: {
line 09: }
line 10:
line 11: class myOuterClass
line 12: {
line 13: public static void main (String args[])
line 14: {
line 15: new mySubClass();
line 16: }
line 17: }
line 18: }
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Shanel
The errors encounterd at mentined luines because u
doesnot provide any no arguments constructor for ur
Superclass. Add no argument constructor to ur
superclass and the code will compile fine
 
Shanel Jacob
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I removed the argument contructor in line 03 already. Doing so removes the first error. There are still 2 more errors.

line 15 error: non-static variable this cannot be referenced from a static context.

line 13 error: inner classes cannot have static declarations public static void main (String args[])

Can you elaborate more? Here's the updated code. Thank you.

line 01: class mySuperClass
line 02: {
line 03: mySuperClass()
line 04: {
line 05: }
line 06:
line 07: class mySubClass extends mySuperClass
line 08: {
line 09: }
line 10:
line 11: class myOuterClass
line 12: {
line 13: public static void main (String args[])
line 14: {
line 15: new mySubClass();
line 16: }
line 17: }
line 18: }
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This code will compile. In your code mySubClass and myOuterClass are inner for mySuperClass, but non-static inner class couldn't have static method
line 01: class mySuperClass
line 02: {
line 03: mySuperClass()
line 04: {
line 05: }
line 06: }

line 07: class mySubClass extends mySuperClass
line 08: {
line 09: }
line 10:
line 11: class myOuterClass
line 12: {
line 13: public static void main (String args[])
line 14: {
line 15: new mySubClass();
line 16: }
line 17: }
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi try in this way



class mySuperClass
{
mySuperClass(int i)
{
}
class mySubClass extends mySuperClass
{
mySubClass(int i){
super(i);// needed when u inherit a class
}
}
static class myOuterClass// needed to b declared static b'cus it contains static method
{
public static void main (String args[])
{
mySuperClass ob = new mySuperClass(3);

}
}
}
 
what if we put solar panels on top of the semi truck trailer? That could power this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic