Results 1 to 3 of 3
  1. #1
    vknehra10 is offline Senior Member
    Join Date
    Dec 2016
    Posts
    103
    Rep Power
    0

    Default whats the problem in functions ?

    when im trying to call functions it shows some error ....


    Stu.java:29: error: cannot find symbol
    System.out.println("Name : "+s.getName+"Age : "+s.getAge); // caret is on "."

    symbol: variable getName
    location: variable s of type Stu
    Stu.java:29: error: cannot find symbol
    System.out.println("Name : "+s.getName+"Age : "+s.getAge); // caret is on "."

    symbol: variable getAge
    location: variable s of type Stu



    Java Code:
    public class Stu
    {
         String name;
    	 int age;
        public void setName(String nm)
    	{
    	    name=nm;
    	}
    	public void setAge(int x)
    	{
    	     age=x;
    	 
    	 }
    
    	 public int getAge()
    	 {
    	 return(age);
    	}
    	public String getName()
    	{
    	 return(name);
    	}
    	
    	public static void main(String Dev[])
    	{
    		Stu s=new Stu();
    		s.setName("vivek");
    		s.setAge(20);
    		System.out.println("Name : "+s.getName+"Age : "+s.getAge);
    	}
    	 }
    Last edited by vknehra10; 01-21-2017 at 03:03 PM.

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: whats the problem in functions ?

    getName is a method. Requires ().

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    vknehra10 is offline Senior Member
    Join Date
    Dec 2016
    Posts
    103
    Rep Power
    0

Similar Threads

  1. Replies: 3
    Last Post: 05-07-2012, 12:39 PM
  2. Trigonometric Functions Problem In Java
    By javaBeaner in forum Advanced Java
    Replies: 11
    Last Post: 12-13-2011, 07:33 PM
  3. Replies: 3
    Last Post: 07-19-2011, 12:12 AM
  4. 2 functions
    By baze7 in forum New To Java
    Replies: 3
    Last Post: 08-14-2009, 04:41 AM
  5. Functions in jsp
    By samson in forum JavaServer Pages (JSP) and JSTL
    Replies: 3
    Last Post: 03-25-2009, 10:04 PM

Tags for this Thread

Posting Permissions

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