Object Oriented Programming Concept
Class and object:
class Count
{
public static void main(String args[])
throws java.io.IOException
{
int count = 0;
while (System.in.read() != -1)
count++;
System.out.println("Input has " + count +"chars.");
}
}
In the Java language, all methods and variables must exist within a class. So, the first line of the character-counting application defines a class, Count
, that defines the methods, variables, and any other classes needed to implement the character-counting application. Since this program is such a simple one, the Count class just defines one method named main()
.
No comments:
Post a Comment