- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
3 ways to initialize an object in Java
Consider a class Tester which has implemented Cloneable interface. Now you can initialize an object using following three ways −
1. Using new keyword.
Tester tester1 = new Tester();
2. Using Class.forName() method
Tester tester4 = (Tester)Class.forName("Tester").newInstance();
3. Using clone method.
Tester tester2 = tester1.clone();
Advertisements