TAILIEUCHUNG - Java Programming for absolute beginner- P10

Java Programming for absolute beginner- P10:Hello and welcome to Java Programming for the Absolute Beginner. You probably already have a good understanding of how to use your computer. These days it’s hard to find someone who doesn’t, given the importance of computers in today’s world. Learning to control your computer intimately is what will separate you from the pack! By reading this book, you learn how to accomplish just that through the magic of programming. | 2 25 03 8 51 AM Page 138 k 0 c c 0 2 V 0 a c S S s k a o k Q. S s public void add Test tt Now the Test class defines two integer variables x and y. In main you declare a Test object t and set to 1 and to 2. Next you call the add method only this time it accepts a Test object reference instead of two primitive data types as its argument. The reference to t is named tt within the method. You can see that it does the same thing as in the previous example. It adds up two variables values and stores the result in the first variable. The difference here is that these variables belong to the Test object which is referenced by both t outside the method and tt inside the method . When you reassign the variable the value becomes 3 and is printed. When control returns to main the value of will reflect this change and will be 3 too. It s like when you call the plumber to come and fix your toilet. You don t send him a clone of your toilet you tell him where it is so he can work his magic and when he s done your toilet is fixed. It s the same concept here you tell the method where your object is and then it goes and operates on it and when it s done your object might have changed. Method Overloading Another important parameter-passing concept for you to learn is method overloading. When two methods have the same name but have different types or numbers of arguments the method is overloaded. Methods names are not unique you can have two different methods with the same name that do two different things if their signatures are different. Consider these three methods method accepts two int arguments public void add int a int b a b a method accepts three int arguments public void add int a int b int c a b c a method accepts two double arguments public void add double a double b a b a team Line - live informative Non-cost and Genuine Please purchase PDF .