Slide 1
Slide 2
Slide 3

Class Method with Return Value in java programming (V56)

No Comments

Example 3: Class Method with Return Value
TextTool class with a method that returns a string in uppercase 


 Create Project Name: TextUpper

Source Code1: TextTool.java

Copied!
public class TextTool {
    // Method that takes a string and returns it in uppercase
    public String toUpper(String text) {
        return text.toUpperCase();
    }
}

Source Code2: TextUpper.java

Copied!
public class TextUpper {
    public static void main(String[] args) {
        TextTool tool = new TextTool();

        String result1 = tool.toUpper("hello my student");
        String result2 = tool.toUpper("java is fun");

        System.out.println("Uppercase: " + result1);   // Output: HELLO My STUDENT
        System.out.println("Uppercase: " + result2);   // Output: JAVA IS FUN
    }
}

Result:


Watch the video:

back to top