When do you create multiple Classes in java, i know classes contain variables and methods and methods,and methods are used to perform some operation, that may be invoked later in the progam. if this can be done why use multiple classes?
Why can''t we use one class and put all methods in that class, please explain me when do you actually create multiple classes.
If my question is silly, i sincerely apologize but i really want to know the answers for my question.
解决方案
Using classes and objects is part of a programming paradigm, called Object Oriented Programming[^]. You''r right you can force an OO language, like Java, to behave like old fashioned procedural languages. But only to a specific level. When you use java, you will see, that you need to use "ready-made" classes and objects instantiated from classes to achieve what you want. You will later realize, that these classes are concentrated around a specific task: some are for handling file system objects, some are for displaying gui, some for more abstract jobs, like collections. The developers could have put all methods in the same class, but than it would have been grown huge, and would have become unusable - and because of the missing encapsulation it would have been put much more coding burden on your shoulders. Using OOP (including classes among other concepts) helps developer make more structured applications, thus easier handling of complexity and maintainability.
Sort of... :)
Because it keeps related stuff together, and means that you can change one (small) part of the code without considering effects on others.
If you have one big class it is the same as the older way of doing things - a monolithic program. Since all methods in your single class have equal access to all other methods, you cannot change any one method without checking carefully that it is not being used in a way you hadn''t intended by an unrelated part of the code.
Keeping things small and separate forces you to define the ways in which they can interact, and improves the overall reliability of your software, as well as the readability, and maintainability.
You really need to go and look at a good description of Object Oriented Programming, as there is a lot more to this than can be covered here.
Take a look at the Java tutorials[^] which explain these concepts in simple terms with real world examples.