Shashwat

Shashwat's Page

Polymorphism Notes

- The ability of a reference variable to change behavior according to what object instance it is holding. In a derived class, the constructors are not transferred. use use the word inherited... constructors are not inherited You have to say super; Basically, when there are methods in the super class that are overriden in the sub class,the super class methods are overriden in the client class. the sub class overridden methods are implemented by the client class even though the object reference variable type is of super class. This mechanism of deciding which overridden method should be implemented is called polymorphism. For e.g. Payment p1 = Payment(50000); Payment cp1 = Cashpayment(12000); Payment crp1 = CreditPayment(60000); They are all Payment objects, but they can access the methods of the object instance (to the right); i.e. p1 can only access Payment methods, by cp1 can access CashPayment methods, etc misunderstood. The first one is aPayment Object. Second one is a CashPayment Object and the third one CreditPayment Object. CashPayment methods and Credit Payment methods will be available only when you cast them to their real object type because of their reference variable type is Payment.....Please talk to me and clarify yourselves

Please explain the following to me This type of polymorphism is used in arrays, where only one database is needed with only one data type. In this case, Polymorphism makes sense.

Abstract Classes Notes

- Abstract classes -Atleast one method is not explicitly implemented. --- Atleast one method is abstract --- better way of saying it.... -You have to mention public abstract class  -For method, public abstract in the sub classes which are not abstract, or else there will be an abstraction error. compile time error - This method can be implemented

I know you have understood everything. However, I would like this notes to be more detailed so when you go back after one month, you will understand what you are talking about. rewrite a detailed one..... GV
 * 1) - You can't form objects from abstract classes, since not all methods are implemented.
 * 2) usually, an abstract class has at least one sub class.

Recursion Notes:

Recursion is basically a method that repeats itself, i.e. in its implementation, it implements itself. This is shown by the following method, which can be used to find the sum of triangular numbers:

public static int triangle (int n) { if(n == 1) return 1; else n + triangle (n-1); }

There are 3 basic requirements for a recursive method to work:

1. A base case: Every recursive method must have a base case for which the value is known. 2. A logic that eventually leads to this base case. This allows the recursive method to end at the base case, and not go on an infinite loop.

Important notes: There need not be one base case; there can be 2 or 3 base cases as well. To identify recursion, there will always be an if-else statement in the method. the else statement will have the recursive formula, while the if statement will have the base case in it.


 * good..... **