How to Solve the Syntax Error in java??
1 Answer(s)      4 years and 11 months ago
Posted in : Java Beginners

Syntax error in java? i have tried this program its showing error like this in Eclipse "Syntax error on token "i", VariableDeclarator expected after this token" . in last line of the program "objectname.i"

What is the reason for this error??How to access the variable "i"

import java.util.Scanner; public class constructors { int i ; private int j; private int k;

public static void main(String args[]) { System.out.println("Enter the name:");

} } class constructor{ constructors objectname = new constructors(); Scanner myScanner = new Scanner(; objectname.i ; }

View Answers

December 2, 2010 at 10:50 AM

Hello Friend,

Actually your syntax is not correct.

Anyways, try the following code:

import java.util.*;

    class constructor{
        int i=0;
        Scanner input=new Scanner(;
        System.out.print("Enter number: ");
    public class constructors{
        public static void main(String args[]){
        constructor con=new constructor();