Results 1 to 3 of 3
  1. #1
    CruelSoulz is offline Member
    Join Date
    May 2013
    Posts
    19
    Rep Power
    0

    Question Problem with visibility modifier

    Java Code:
        private static int validateMark(){
        	
        	private boolean status = false;
        	private int mark = 0;
        	
        	while(status == false)
        	{
    	    	try{
    	    		mark = scanner.nextInt();
    	    		status = true;
    	    	}
    	    	catch(java.util.InputMismatchException e){
    	    		
    	    		status = false;
    	    		
    	    		System.out.println("-- Please Enter Integer Value --");
    	    		scanner.nextLine();// Consume token
    	    		
    	    	}
        	}
        	
        	return mark;
        	
        }
    I don't understand why when i'm putting private modifier for "status" variable and "mark" variable it give me 2 errors :

    G:\Java\JavaPractical\P8\P8Q1\testDriver.java:79: error: illegal start of expression
    private boolean status = false;
    ^
    G:\Java\JavaPractical\P8\P8Q1\testDriver.java:80: error: illegal start of expression
    private int mark = 0;
    ^
    2 errors
    Anyone can help me? Thanks ...

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,041
    Rep Power
    10

    Default Re: Problem with visibility modifier

    Assuming this is a function inside a valid class, the lines the compiler is complaining about don't make sense for the following reason:

    What does it mean for a variable defined inside a method to be private? The variable will go out of scope as soon as the method return anyway.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    CruelSoulz is offline Member
    Join Date
    May 2013
    Posts
    19
    Rep Power
    0

    Default Re: Problem with visibility modifier

    Oh ... now i only realize that it really don't make any sense ... haha, thanks for explanation

Similar Threads

  1. Set visibility of parent Container
    By mwr1976 in forum AWT / Swing
    Replies: 2
    Last Post: 04-14-2012, 03:37 AM
  2. Java, Reset Visibility Of An Object
    By Alerhau in forum New To Java
    Replies: 1
    Last Post: 08-11-2011, 12:53 AM
  3. Help! set dinamically visibility of panels
    By unkus_nob in forum JavaFX
    Replies: 5
    Last Post: 06-21-2011, 10:06 PM
  4. Java Visibility
    By efozdel in forum New To Java
    Replies: 8
    Last Post: 07-07-2010, 04:36 AM
  5. Newbie help on visibility and static final
    By tornado in forum New To Java
    Replies: 3
    Last Post: 11-28-2008, 02:32 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •