Worksheet (Constructor)
1. What do you mean by Constructor? Give example.
2. Write features of Constructor.
3. Give differences between a Constructor and a Method.
4. Differentiate between static and non- static data members.
5. Name the types Constructor.
6. Define Default Constructor. Give example.
7. Explain Parameterized Constructor with example.
8. What is Copy Constructor?
9. Discuss Constructor Overloading with example.
Worksheet(Array)
1. Define Array.
2. Write the different ways to declare to Array.
3. Name types of Array.
4. Name the basic operations in Array.
5. Name the types of Search.
6. Define Linear Search.
7. Discuss Binary Search technique.
8. Differentiate between Linear Search and Binary Search.
Assignment 1
Define Function/Method with example.
What is the significance of return in terms of Method in Java?
What is void in terms of Method in Java?
Write a program to find square and cube with the following method names:
void squareOfANumber( ), void cubeOfANumber( ).
Write a program to find whether the number is Positive or Negative and Odd or Even with the following method names:
void positiveOrNegative( ), void oddOrEven( ).
Write a program to find area of Rectangle, Triangle and Circle with the following method names:
void areaOfRectangle( ), void areaOfTriangle( ), void areaOfCircle( ).
Write a program to find Simple Interest with the following method name:
void simpleInterest(float p, float r, float t).
Write a program to find area of Rectangle, Triangle and Circle with the following method names:
void areaOfTriangle(float b, float h ), void areaOfCircle(float r).
Write a program to print Sum of Natural Numbers and Factorial, with the following method names:
void sumOfNaturalNumbers(float n), void factorialOfANumber(float n).
Write a program to accept marks obtained in English, Hindi, Math, Science and Computer Applications and calculate the total and percentage and find the grade with the following method name:
char calculateGrade(float e, float h, float m, float s, float ca)
Assignment 2
1. Explain the following terms:
Header, Function Prototype, Function Signature, Access-Specifier, Return Type
2. Write the features of return type.
3. Difference between Actual and Formal Parameters.
4. Explain Pure and Impure function with example.
5. Explain Function Overloading with example.
6. Design a class to overload a function series() as follows:
(i) double series(double n) with one double argument and returns the sum of the series.
sum = 1/1 + 1/2 + 1/3 + ….. 1/n
(ii) double series(double a, double n) with two double arguments and returns the sum of the series.
sum = 1/a2 + 4/a5 + 7/a8 + 10/a11 ….. to n terms
7. Define a class called Library with the following description:
Instance variables/data members:
int acc_num – stores the accession number of the book
String title – stores the title of the book stores the name of the author
Member Methods:
(i) void input() – To input and store the accession number, title and author.
(ii) void compute – To accept the number of days late, calculate and display and fine charged at the rate of Rs.2 per day.
(iii) void display() To display the details in the following format:
Accession Number Title Author
Write a main method to create an object of the class and call the above member methods.
8. Define a class named MovieMagic with the following description:
Instance variables/data members:
int year – to store the year of release of a movie
String title – to store the title of the movie.
float rating – to store the popularity rating of the movie.
(Minimum rating = 0.0 and maximum rating = 5.0)
Member Methods: (i) Movie Magic() Default constructor to initialize numeric data members to 0 and String data member to
(ii) void accept() To input and store year, title and rating.
(iii) void display() To display the title of a movie and a message based on the rating as per the table below.
Rating Message to be displayed
0.0 to 2.0 Flop 2.1 to 3.4 Semi-hit
3.5 to 4.5 Hit 4.6 to 5.0 Super Hit
Write a main method also to create an object of the class and call the above member methods.