Page 463 - CA_Blue( J )_Class10
P. 463
22 }
23 }
24 public static void main() // Declaration of main()
25 {
26 Scanner sc= new Scanner(System.in);
27 int n1;
28 System.out.println("Enter nth term ");
29 n1=sc.nextInt();
30 fibonacci ob= new fibonacci(n1); // Creating object of class
fibonacci
31 ob.display(); // Invoking display()
32 } // close of main()
33 } // close of class
Output
Enter nth term
5
The first 5 fibonacci series : 0 1 1 2 3
Variable Description
NAME DATATYPE DESCRIPTION
st
a int Instance Variable to store 1 number
nd
b int Instance Variable to store 2 number
rd
c int Instance Variable to store 3 number
n int Instance Variable to store nth term
n1 int Local Variable to enter nth term
i int Loop variable
(b) Programs based on constructor overloading.
class : rectangle
Program 8
Data Members : int l, b, a, p
Methods :
rectangle() : Non-parameterized constructor to initialize l=8, b=4, a=0, p=0
rectangle(int l1, int b1) : Parameterized constructor to initialize l1 to l and b1 to b
rectangle(rectangle r) : Copy Constructor
void calculate() : used to calculate the a and p
void display() : used to display a and p
1 import java.util.*; //importing package "util"
2 class rectangle // Declaration of class rectangle
461
Internal Assessment 461

