File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Compiler errors at line 7, 15 & 13 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Compiler errors at line 7, 15 & 13" Watch "Compiler errors at line 7, 15 & 13" New topic
Author

Compiler errors at line 7, 15 & 13

Shanel Jacob
Ranch Hand

Joined: Jun 18, 2006
Posts: 112
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: }
swarupa patil
Ranch Hand

Joined: Feb 22, 2006
Posts: 62
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

Joined: Jun 18, 2006
Posts: 112
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: }
Vladimir Scheglov
Greenhorn

Joined: Jun 19, 2006
Posts: 20
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: }
jerry sharma
Greenhorn

Joined: Mar 30, 2006
Posts: 23
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);

}
}
}
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Compiler errors at line 7, 15 & 13
 
Similar Threads
Doubt in Static Methods
polymorphism question
overriding static methods
Trying to cast sibling types and interfaces
question from mughals book