code issue

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
LVL 7
gudii9Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David FavorLinux/LXD/WordPress/Hosting SavantCommented:
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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Owen RubinConsultantCommented:
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?
girionisCommented:
You need to put
this.test();

Open in new window

inside a method body.
Owen RubinConsultantCommented:
Damn, missed that myself. Good catch girionis.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.