M
M
Marat2015-12-20 20:02:54
Java
Marat, 2015-12-20 20:02:54

How to create an object knowing the name of its class?

How can you implement the creation of objects knowing which * .java is in the folder? Let me explain: there is a folder in which there are different *.java, they are inherited from a common abstract class. (Made in order to expand the functionality in the future). You need to know the name of the class so that you can create an object based on it.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
nirvimel, 2015-12-20
@nirvimel

Object object = Class.forName(className).getConstructor().newInstance();

K
Konstantin Malyarov, 2015-12-20
@Konstantin18ko

cat:
parameters:
int size;
int age;
methods:
lickeggs();
enrage the host();
We create our personal library consisting of one class.
We connect it to the project.
So it doesn't roll?
Or I didn't understand the question?
PS Just create a library from one class. Well, or from several.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question