Code Snippet for checking variable type in java

class Main
{

public static void main (String[] args) throws java.lang.Exception
{
	
	Integer a = 1;
	String b = "ABC";
	Object c = a;
	Object d = b;
	
	if(c instanceof Integer && d instanceof String){
	System.out.println(" c is of type Integer and d is of type String");
}else{
	System.out.println(" Some error detected ");
}

}

Comments (0)
No comments yet.