Three Ways to Create Instances

I had a small interview with CRA this morning, and did terribly on the Java section. That’s probably because I didn’t know it was going to be on Java, a language I haven’t programmed in for 2 years. I thought one question was pretty interesting though:

Name three ways to create an instance of a class.

The first way is easy, using the new keyword with the constructor. The other two are trickier.
Using the clone keyword in the Object class was the second answer, which was kind of obvious once you think about it. It basically creates a new class by copying an old one…
The last one is one that he didn’t expect people to know, which was to use the forname function in the Object class. From his explanation, what it allows one to do is to probe an unknown class.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.