Last active
September 28, 2023 14:33
-
-
Save sovietspy2/f743876fb21073f9b6a7350139c3d4e5 to your computer and use it in GitHub Desktop.
much java so safe
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.example.inheritance; | |
import java.lang.reflect.Field; | |
public class Main2 { | |
public static void main(String[] args) { | |
Child child = new Child(); | |
child.list(); | |
} | |
public static class Parent { | |
private Integer value = 1; | |
Parent() { | |
System.out.println("Parent ()"); | |
} | |
} | |
public static class Child extends Parent { | |
Child() { | |
super(); | |
} | |
public void list() { | |
Field[] fields = getClass().getSuperclass().getDeclaredFields(); | |
// Make private fields accessible and print their names | |
for (Field field : fields) { | |
field.setAccessible(true); | |
System.out.println("Field Name: " + field.getName()); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment