Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7979951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:55:14+00:00 2026-06-04T09:55:14+00:00

We can use reflection to create the objects. Let’s say I have a class

  • 0

We can use reflection to create the objects. Let’s say I have a class “Employee” in package p

Employee emp = Employee.class.newInstance()  OR
Employee emp = (Employee)Class.forName("p.Employee").newInstance() 

Above lines of code will create Employee object by calling Employee’s default or no-arg constructor. And then I set some values to objects by calling setters of Employee

Is there any way of creating objects using reflection by giving values in the constructor itself i.e. by calling parameterized constructor?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T09:55:16+00:00Added an answer on June 4, 2026 at 9:55 am

    Take a look at Class.getConstructor and Constructor.

    First you get the right constructor by its parameter types, then you call it with arguments of that type:

    Constructor<Employee> constructor = Class.forName("p.Employee").getConstructor(Integer.class, String.class);
    Employee employee = constructor.newInstance(1,"foo");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I use reflection to create a generic List with a custom class
I came to know that using Reflection we can create objects without using new
Let's say I have an abstract class: abstract class Foo extends Bar { public
You can use more than one css class in an HTML tag in current
I can use VS08's MFC/ActiveX template to create a C++ ActiveX object that I
I'm trying to use one of the simplest forms of reflection to create an
I am attempting to use reflection to determine which Properties of a Type have
I have a general question about data templates in WPF. Let's say I have
I can use vi{ and va{ to select C++ code blocks. It helps me
I can use the regex comparing a comma delimited list of GUID against a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.