

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What are the different ways to create an object in Java
We can create object using multiple ways. Using new keyword is most prevalent one. Following are the various ways to create/initialize objects.
Using new keyword.
Tester tester1 = new Tester();
Using Class.forName() method
Tester tester2 = (Tester)Class.forName("Tester").newInstance();
Using clone method.
Tester tester3 = tester1.clone();
Using Constructor.forName() method
Tester tester4 = Tester.class.getConstructor().newInstance();
Using Deserialization
ObjectInputStream objectInputStream = new ObjectInputStream(inputStream ); Tester tester5 = (MyObject) objectInputStream.readObject();
- Related Questions & Answers
- Different ways to create an object in java?
- What are the different ways to print an exception message in java?
- What are the different ways to iterate over an array in Java?
- Different ways to create Objects in Java
- What are all the ways an object can be created in Java?
- What are the different ways to install pandas?
- 5 different ways to create objects in Java
- What are the different ways of copying an array into another array in Java?
- What are the different ways of cooking eggs?
- Different ways to traverse an Array in Java?
- 3 ways to initialize an object in Java
- What are the different ways to include dry fruits in our diet?
- What are the different ways to select an option from a dropdown using Selenium Webdriver?
- What are the different ways the transaction can be executed(DBMS)?
- What are different ways of defining functions in JavaScript?
Advertisements