You forgot the constructor.
class class2 extends class1 {
class2() {
super();
}
void msg() {
System.out.println("Hello class1");
}
}
Question
I am using netBeans7.3.1 and getting error *illegal start of type * even though I have written super() as the irst line of class2.
package javaapplication9;
class class1 {
class1() {
System.out.print("class1 constructor");
}
void msg() {
System.out.println("Hello class1");
}
}
class class2 extends class1 {
super();
void msg() {
System.out.println("Hello class1");
}
}
public class JavaApplication9 {
public static void main(String[] args) {
class1 obj = new class1();
obj.msg();
}
}
La solution
You forgot the constructor.
class class2 extends class1 {
class2() {
super();
}
void msg() {
System.out.println("Hello class1");
}
}
Autres conseils
It should be inside the constructor of your sub class.
class class2 extends class1 {
class2() {
super();
}
So that it invokes your super class constructor when you create subclass object.