Dis Practical-9

public class StringLengthUsingThread {
    public static void main(String[] args) {
        // Sample string
        String inputString = "Indus university";
        // Create and start the thread
        StringLengthThread thread = new StringLengthThread(inputString);
        thread.start();
    }
}
class StringLengthThread extends Thread {
    private String str;

    // Constructor to initialize the string
    public StringLengthThread(String str) {
        this.str = str;
    }

    // Override run method to calculate string length
    @Override
    public void run() {
        System.out.println("Length of the string: " + str.length());
    }
}

Leave a Comment

Your email address will not be published. Required fields are marked *

error: Content is protected !!
Scroll to Top