Sitara

Sitara's Page

A recursive method is a method that calls itself It is another control mechanism Recursion can accomplish repetitive tasks like a loop A valid recursion must always have a base case and a logic which leads to it The strategy is to find some easily applied action that breaks the problem into smaller pieces. Some can be dealt with immediately, and others need to be broken up (base case can be dealt with, recursive call has to be broken down)

Import java.util.Scanner; Public class TriangleNumbers { public static void main (String args []) { Scanner console = new Scanner(System.in) System.out.println(“Enter a number of rows for triangle numbers: “); Int n = console.nextInt; System.out.println(“The total pins = “ + triangle(n)); } public static int triangle( int n) { if (n ==1) return 1; else return n + triangle(n-1); } } Sitara Abstract Class Notes abstract class should contain at least one abstract method A n //abstract class// is a class that is declared abstract. This means that it may or may not include abstract methods. Abstract classes cannot be instantiated, but they can be subclassed. An //abstract method// is a method that is declared without an implementation. When an abstract class is subclassed, the subclass usually provides implementations for all of the abstract methods in its parent class. -- good understanding Steps
 * good notes sitara.... let me know if there is any problem **
 * declare an abstract class
 * provide member variables and methods that are wholly shared by all subclasses.
 * These methods need to be implemented by all subclasses
 * However they must be implemented in different ways.

Polymorphism in java is when one variable can denote multiple objects, it is used in inheritance and interfaces. There are two types of polymorphism: overloading and inclusion. you don't need these types of polymorphism for AP exam. I would recommend you could study additional information after you complete your AP work...
 * Polymorphism**

//Overloading polymorphism// occurs when a child class overrides the method implementation of the parent class.

//Inclusion polymorphism// occurs if a child class inherits its method substance from the base or parent class

Example of a polymorphic class

public class Payment { private double amount; private String details; public Payment (double a, String descrip) { amount = a; details = descrip; } public void setamount(double newa) { amount = newa; } public void setdetails (String descrip) { details = descrip; } public String getdetails { return details; } public double getamount { return amount; } public void paymentdetails(String descrip) { System.out.println("Payment is for" + descrip); } public String toString { return "This payment of RS " + amount + "/t" + "is for " + details; } }

This is the superclass. The subclass will include the implemented methods of the parent class, making it inclusion polymorphism.

public class Cashpayment extends Payment { public Cashpayment(double amount, String descrip) { super(amount); } public void paymentDetails (String describe) { super.setDetails(describe); System.out.println("I am from Cashpayment subclass" + describe); } } good.... comparison between Interfaces and Abstract Classes????