-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDemo1.java
More file actions
50 lines (43 loc) · 1.16 KB
/
Copy pathDemo1.java
File metadata and controls
50 lines (43 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Scanner;
class A
{
static{
System.out.println("A Class Loaded...");
}
A(){
System.out.println("A Class Cons Call");
}
private void show(){
System.out.println("Show Call");
}
}
class B{
static{
System.out.println("B Class Loaded...");
}
B(){
System.out.println("B Class Cons Call");
}
void disp(){
System.out.println("Disp call");
}
}
public class Demo1 {
public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchMethodException, SecurityException, IllegalArgumentException, InvocationTargetException {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the Class Name");
String className = scanner.next();
Object object = Class.forName(className).newInstance();
System.out.println("Enter the Method Name");
String methodName = scanner.next();
Method method = object.getClass().
getDeclaredMethod(methodName);
method.setAccessible(true);
method.invoke(object);
// Class obj = new ClassName()
//A obj = new A();
//Object o = new B();
}
}