MyClass.java Source code

Java tutorial

Introduction

Here is the source code for MyClass.java

Source

import java.lang.reflect.Field;

class MyClass {
    public char i = 'c';
}

public class Main {
    public static void main(String[] args) throws Exception {
        Class<?> clazz = Class.forName("MyClass");
        MyClass x = (MyClass) clazz.newInstance();

        Field f = clazz.getField("i");
        System.out.println(f.getChar(x));

        f.setChar(x, 'a');
        System.out.println(f.getBoolean(x));

    }
}