Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
4.7k views
in Computer by (79.0k points)

A super class Number is defined to calculate the factorial of a number. Define a sub class Series to find the sum of the series S = 1! + 2! + 3! + 4! + ........ + n ! 

The details of the members of both the classes are given below :

Class name Number
Data member/instance variable : to store an integer number
Member functions / methods :
Number(int nn) parameterized constructor to initialize the data member n = nn
int factorial(int a) returns the factorial of a number
(factorial of n = 1 × 2 × 3 × ..... × n)
void display ( ) displays the data members
Class name : Series 
Data member/instance variable :
sum to store the sum of the series
Member functions/methods :
Series(...) Parameterized constructor to initialize the data members of both the classes 
void calsum( ) calculates the sum of the given series
void display( ) displays the data members of both the classes

Assume that the super class Number has been defined. Using the concept of inheritance, specify the class Series giving the details of the constructor(...), void calsum( ) and void display( ). The super class, main function and algorithm need NOT be written.

1 Answer

+1 vote
by (76.3k points)
selected by
 
Best answer

class Series extends Number

{

int sum; Series (int nn)

{

super (nn);

sum = 0;

}

void calsum ( )

{

int i;

for (i = 1; i < n; i ++)

{

sum = sum + factorial (i);

}

}

void display ( )

{

system. out. println ("n = "+ n);

system. out. println (" sum of series is " + sum);

}

}

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...