Java Function-Overloading Board Questions


  1. Define a class to overload the method perform as follows: [15 MARKS-2024]

    (i) double perform (double r, double h) — to calculate and return the value of curved surface area of cone
    CSA = πrl, l = √(r2+ h2)

    (ii) ​void perform (int r, int c) — Use NESTED FOR LOOP to generate the following format r = 4, c = 5

    output
    1 2 3 4 5
    1 2 3 4 5
    1 2 3 4 5
    1 2 3 4 5
    
    (iii) void perform (int m, int n, char ch) — to print the quotient of the division of m and n if ch is Q else print the remainder of the division of m and n if ch is R
  2. coming soon

  3. Define a class to overload the function print as follows: [15 MARKS-2023]

    (i) void print() - to print the following format

    1  1  1  1
    2  2  2  2
    3  3  3  3
    4  4  4  4
    5  5  5  5
    
    (ii) void print(int n) - To check whether the number is a lead number. A lead number is the one whose sum of even digits are equal to sum of odd digits.

    e.g. 3669
    odd digits sum = 3 + 9 = 12
    even digits sum = 6 + 6 = 12
    3669 is a lead number.
    
  4. coming soon

  5. Design a class to overload a function series( ) as follows: [15 MARKS-2019]

    (i) void series (int x, int n) – To display the sum of the series given below:
    x1 + x2 + x3 + .......... xn terms

    (ii) void series (int p) – To display the following series:
    0, 7, 26, 63 .......... p terms

    (iii) void series () – To display the sum of the series given below:
    1/2 + 1/3 + 1/4 + .......... 1/10
  6. coming soon

  7. Design a class to overload a function volume() as follows: [15 MARKS-2018]

    (i) double volume (double R) – with radius (R) as an argument, returns the volume of sphere using the formula.
    V = 4/3 x 22/7 x R3

    (ii) double volume (double H, double R) – with height(H) and radius(R) as the arguments, returns the volume of a cylinder using the formula.
    V = 22/7 x R2 x H

    (iii) double volume (double L, double B, double H) – with length(L), breadth(B) and Height(H) as the arguments, returns the volume of a cuboid using the formula.
    V = L x B x H

  8. coming soon

  9. Design a class to overload a function check( ) as follows: [15 MARKS-2017]

    (i) void check (String str , char ch ) — to find and print the frequency of a character in a string.
    Example:
    Input:
    str = "success"
    ch = 's'
    Output:
    number of s present is = 3
    
    (ii) void check(String s1) — to display only vowels from string s1, after converting it to lower case.
    Example:
    Input:
    s1 ="computer"
    Output : o u e
    
  10. coming soon

  11. Design a class to overload a function sumSeries() as follows: [15 MARKS-2016]

    (i) void sumSeries(int n, double x): with one integer argument and one double argument to find and display the sum of the series given below:
    s=x/1−x/2+x/3−x/4+x/5... ... ... to n terms

    (ii) void sumSeries(): to find and display the sum of the following series:
    s=1+(1×2)+(1×2×3)+... ... ... +(1×2×3×4... ... ... ×20)
  12. coming soon

  13. Design a class to overload a function Joystring( ) as follows: [15 MARKS-2015]

    (i) void Joystring(String s, char ch1, char ch2) with one string argument and two character arguments that replaces the character argument ch1 with the character argument ch2 in the given String s and prints the new string.
    Example:
    Input value of s = "TECHNALAGY"
    ch1 = 'A'
    ch2 = 'O'
    Output: "TECHNOLOGY"
    
    (ii) void Joystring(String s) with one string argument that prints the position of the first space and the last space of the given String s.
    Example:
    Input value of s = "Cloud computing means Internet based computing"
    Output:
    First index: 5
    Last Index: 36
    
    (iii) void Joystring(String s1, String s2) with two string arguments that combines the two strings with a space between them and prints the resultant string.
    Example:
    Input value of s1 = "COMMON WEALTH"
    Input value of s2 = "GAMES"
    Output: COMMON WEALTH GAMES
    (Use library functions)
    
  14. coming soon

  15. Design a class to overload a function polygon() as follows: [15 MARKS-2014]

    (i) double area (double a, double b, double c) with three double arguments, returns the area of a scalene triangle using the formula:
    area = √(s(s-a)(s-b)(s-c))
    where s = (a+b+c) / 2

    (ii) double area (int a, int b, int height) with three integer arguments, returns the area of a trapezium using the formula:
    area = (1/2)height(a + b)

    (iii) double area (double diagonal1, double diagonal2) with two double arguments, returns the area of a rhombus using the formula:
    area = 1/2(diagonal1 x diagonal2)

  16. coming soon

  17. Design a class to overload a function series( ) as follows: [15 MARKS-2013]

    (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

  18. coming soon

  19. Design a class to overload a function polygon() as follows : [15 MARKS-2012]

    (i) void polygon (int n, char ch) - with one integer argument and one character type argument that draws a filled square of side n and using the character stored in ch.

    (ii) void polygon (int x, int y) - with two integer arguments that draws a filled rectangle of length x and breadth y using the symbol ‘@’.

    (iii) void polygon () - with no argument that draws a filled rectangle shown below.

    Example :
    
    (i) Input value of n=2, c= ‘O’
    Output : 
    OO
    OO
    
    (ii) Input value of x=2, y=5
    Output : 
    @@@@@
    @@@@@
    
    (iii) Output : 
    *
    **
    ***
    ****
    
  20. coming soon

  21. Design a class to overload a function compare( ) as follows:[15 MARKS-2011]

    (i) void compare(int, int) — to compare two integers values and print the greater of the two integers.

    (ii) void compare(char, char) — to compare the numeric value of two characters and print with the higher numeric value.

    (iii) void compare(String, String) — to compare the length of the two strings and print the longer of the two.

  22. coming soon

  23. Write a class with the name volume using function overloading that computes the volume of a cube, a sphere and a cuboid. [15 MARKS-2008]

    Formula
    volume of a cube (vc) = s x s x s
    volume of a sphere (vs) = 4/3 x π x r x r x r (where π = 3.14 or 22/7)
    Volume of a cuboid (vcd) = l x b x h

  24. coming soon