Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Lv 43,052 points

MANOJ

Favorite Answers81%
Answers236

I'm a professional software programmer. http://javacodespot.blogspot.com/

  • Java Help? is it possible to write a better code than this..?

    public void myMethod(Object obj) {

    try {

    String x = (String) obj;

    System.out.println(x.length());

    } catch (ClassCastException e) {

    System.out.println(" The passed object is not string");

    } catch (NullPointerException e) {

    System.out.println(" The passed object is not string");

    }

    }

    this method prints the length of the string if the passed object is a string, else it prints the message that the passed object was not a string. Can you write a better code?

    2 AnswersProgramming & Design1 decade ago