in my text book, i have seen examples containing of two classes. one class contianing methods that perfom useful tasks and one containing method main, which creates an object of the other class and calls its method! for the life of me i can't understand why we would take such approach? thanks in advance.
Such approach is made simply because its more efficient and somewhat more straight forward, why you might ask.. because instead of recoding such method/s to every class that needs it why dont you just create a utility class with all the common methods that you need in all of your classes then just call it when you need it..
Let's say the class with useful methods is mum class. In baby class mum will give birth to new baby. But you won't want to know how baby is created, or so to say the whole process inside mum class is hidden from baby class view.
Also you can always reuse the mum class. You can create different baby with type boy or girl. But you won't haveto rewrite new mum class everytime.
So if your textbook is showing a simple class, and a main() routine in another class making use of that first class, the book is just trying to give you a small taste of this idea, that real programs are made up of many classes working together, each with a well-defined role.
a. Class Creation - done by a class creator
b. Class Usage - done by a client programmer
So, any programmer is always a class creator as well as a client programmer. In this example, one class is "created" and another demonstrates its use.