Sunday, 20 March 2022

Java: How to check whether given class is an interface or not?

'java.lang.Class' provides 'isInterface' method, which return true if the given class is an interface, else false.

 

ClassInterfaceCheck.java

package com.sample.app;

import java.io.Serializable;

public class ClassInterfaceCheck {

	public static void main(String[] args) {
		System.out.println("Is System class represent an interface? : " + System.class.isInterface());
		System.out.println("Is Deprecated class represent an interface? : " + Deprecated.class.isInterface());
		System.out.println("Is Serializable class represent an interface? : " + Serializable.class.isInterface());
	}

}

 

Output

Is System class represent an interface? : false
Is Deprecated class represent an interface? : true
Is Serializable class represent an interface? : true

 

 

 

Previous                                                    Next                                                    Home

No comments:

Post a Comment