This will not run, and I am pulling it straight from the how-to....

public class add
{ 
	public static void main(String[] args) 
	{ 
		int sum = add(5, 2);
		System.out.println("Sum is " + sum);
		
		public static int add(int firstInt, int secondInt)
		{
		return firstInt + secondInt;
		}
	}
}

I would love to see the source you are pulling this from. You cannot create a method inside another method.

public class add
{ 
	public static void main(String[] args) 
	{ 
		int sum = add(5, 2);
		System.out.println("Sum is " + sum);
		
		public static int add(int firstInt, int secondInt)
		{
		return firstInt + secondInt;
		} //Wrong!
	}
}
public class add
{ 
	public static void main(String[] args) 
	{ 
		int sum = add(5, 2);
		System.out.println("Sum is " + sum);
		
		
	}
 public static int add(int firstInt, int secondInt)
		{
		return firstInt + secondInt;
		}//Right!
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.