code issue

gudii9
gudii9 used Ask the Experts™
on
package SuperThis;
public class Sub extends Super {
	/*public static void main(String[] args) {
		  super.bar();
	      this.bar();
	}*/
    public void bar() {
        System.out.println("Sub.bar()...");
    }
 
 
    public void test() {
       super.bar();
       this.bar();
    }
  
    	// Sub sub=new Sub();
    	 //   sub.test();
    
        this.test();
}

Open in new window

why above code is not working
i see error as below at line 21,15
Syntax error, insert "}" to complete ClassBody

Please advise
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Fractional CTO
Distinguished Expert 2018
Commented:
Simple way to debug this type of problem.

Comment out all your code.

Then remove comments for each code section (method).

In your case, first glance, looks like this.test(); may be the problem.

Comment out this line + see if your error disappears.

I think you'll have to instantiate an object of SuperThis + then call the test method on your $object.
Commented:
So I guess some code is missing here, but if I compile this I get:


$javac SuperThis/Sub.java

SuperThis/Sub.java:20: error: illegal start of type
        this.test();
        ^
SuperThis/Sub.java:20: error: ';' expected
        this.test();
            ^
SuperThis/Sub.java:20: error: invalid method declaration; return type required
        this.test();
             ^
3 errors

So I am wondering if your compiler just throws that error because it does not know what to do with line 20?
Distinguished Expert 2018
Commented:
You need to put
this.test();

Open in new window

inside a method body.

Commented:
Damn, missed that myself. Good catch girionis.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial