Home Java Programming Language / Programs / Design a class to overload a function check( ) as follows:
🚀 Programming Example

Design a class to overload a function check( ) as follows:

👁 104 Views
💻 Practical Program
📘 Step Learning
Learn this program step-by-step with algorithm, source code, output and detailed explanation.

📌 Information & Algorithm

Design a class to overload a function check( ) as follows:

  1. 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

  2. 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

💻 Program Code

public class RAnsariOverload1
{
    void check (String str , char ch ) {
        int count = 0;
        int len = str.length();
        for (int i = 0; i < str.length(); i++) {
            char c = str.charAt(i);
            if (ch == c) {
                count++;
            }
        }
        System.out.println("Frequency of " + ch + " = " + count);
    }

    void check(String s1) {
        String s2 = s1.toLowerCase();
        int len = s2.length();
        System.out.println("Vowels:");
        for (int i = 0; i < len; i++) {
            char ch = s2.charAt(i);
            if (ch == 'a' ||
                ch == 'e' ||
                ch == 'i' ||
                ch == 'o' ||
                ch == 'u')
                System.out.print(ch + " ");
        }
    }
}
                        
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.