java.lang.reflect.Modifier.isAbstract() Method Example



Description

The java.lang.reflect.Modifier.isAbstract(int mod) method return true if the integer argument includes the abstract modifier, false otherwise.

Declaration

Following is the declaration for java.lang.reflect.Modifier.isAbstract(int mod) method.

public static boolean isAbstract(int mod)

Parameters

mod − a set of modifiers.

Returns

true if mod includes the abstract modifier; false otherwise.

Example

The following example shows the usage of java.lang.reflect.Modifier.isAbstract(int mod) method.

package com.tutorialspoint;

import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

public class ModifierDemo {
   public static void main(String[] args) {

      Method[] methods = SampleClass.class.getMethods();
      System.out.println(Modifier.isAbstract(methods[0].getModifiers()));
   }
}

abstract class SampleClass {
   private String sampleField;
   
   public abstract String getSampleField();
   
   public void setSampleField(String sampleField) {
      this.sampleField = sampleField;
   } 
}

Let us compile and run the above program, this will produce the following result −

true
java_reflect_modifier.htm
Advertisements