UrbanPro

Learn Java Training from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

If a class contains only a private constructor and no other constructor, is it possible to create object of that class? If yes how?

Asked by Last Modified  

17 Answers

Learn Java

Follow 0
Answer

Please enter your answer

Software Developer, Expertise in Java/J2ee Technology.

Yes, It is possible. But, Object can be created only with in that class (either in any method or block).
Comments

using factory method and using reflection concept
Comments

IT Professional Trainer with 15 years of experience in IT Industry

Private constructor creation is not possible.. if constructor create with private access specifier, then class can not create objects..
Comments

Real Time Java

Yes we can create actually it is implementation of singleton design pattern.The following is the example public class DataSource{ public static final DataSource object; private DataSource(){ //we can write any code like jdbc } static{ object=new DataSource(); } // you can have...
read more
Yes we can create actually it is implementation of singleton design pattern.The following is the example public class DataSource{ public static final DataSource object; private DataSource(){ //we can write any code like jdbc } static{ object=new DataSource(); } // you can have other methods according to requirement } read less
Comments

Software Engineer

yes via singlton pattern
Comments

MCA

We can have private contructor also. but using this we can create object with in the class itself, you can not create object from out side of the class. This process can be followed in singleton design pattern by providing a public method to get the same instance which had been created by static block....
read more
We can have private contructor also. but using this we can create object with in the class itself, you can not create object from out side of the class. This process can be followed in singleton design pattern by providing a public method to get the same instance which had been created by static block. I would say don't make the constructor private, don't make the build code under the constructor (place it in a new method, which can be private) and make a method to return the object outside the class. read less
Comments

Tutor taking Computer subjects Classes

Private constructor can be created but it would not be effective as it could not be invoked .
Comments

Industry expert and professional lecturer/trainer

Yes via Singleton Design pattern
Comments

IT professional with over 8 years of hands on experience in Core Java & Telecom

Using Singleton design pattern. private constructors are defined when the project requires that only one object of a class exist. To implement this requirement 1. we will make the constructor as private 2. Create within the class a object in static block or just a private static global variable...
read more
Using Singleton design pattern. private constructors are defined when the project requires that only one object of a class exist. To implement this requirement 1. we will make the constructor as private 2. Create within the class a object in static block or just a private static global variable referring to the object of the class or in a public static method. 3. Have a public static getInstance method which will expose the only one object of the class created read less
Comments

Trainer

Yes you can create Object of that class at anywhere by creating a public method that has the returned type as object and one more thing that Singleton pattern is nothing to do with creating an Object .The singleton Pattern we use is meant for one and only instance of that type in whole application consider...
read more
Yes you can create Object of that class at anywhere by creating a public method that has the returned type as object and one more thing that Singleton pattern is nothing to do with creating an Object .The singleton Pattern we use is meant for one and only instance of that type in whole application consider the following code public class Alpha { private Alpha() { // no -args constructor } public Alpha createInstance() { return new Alpha(); } public static void main(String[]args) { Alpha a1= createInstance(); Alpha a2=createInstance(); } } Now If you want to create Object of Alpha class else where just make create Instance method as follow class Alpha { private Alpha() { // no -args constructor } public static Alpha createInstance() { return new Alpha(); } } public class Beta { public static void main(String[]args) { Alpha a1= Alpha.createInstance(); Alpha a2=Alpha.createInstance(); // Now check whether if those instance are same if(a1.equals(a2)) { System.out.println("Both instance are refering same object"); } else { System.out.println("Both instance are refering different object"); } } } read less
Comments

View 15 more Answers

Related Questions

Is it really needed to do Java training before graduation, to get a job?
Yes, It's must to get better opportunities and to standard alone in IT field. Not only core Java but also learn Spring,Hinernat ,Struts. ANGULARJS add an advantage to get job easily.
Udaybhan
What is the general syllabus covered in core Java training from any institution?
Welcome Course Overview Review of Java Fundamentals The Java Environment Data Types The String Class The StringBuffer Class Arrays Passing Data Types to a Method Constructors &...
Shiv Kohli
0 0
5
Who can provide good Java training with real-time but not institute?
If you reside in pune then i can provide real time programming in java . So you will get to know industry based java programming
Sridevi
0 0
6
What is use of interface in Java language?
Interface are used to code re-usability, and they are the real driver of ploymorphism in Java. Interface are also allows multiple inheritance in java.
Parminder
Which is a good Java training and placement institute for a fresher in Bangalore?
I know an institute in HYderabad which is giving 100% job guarantee or 100% fee refund. They have office in bangalore also, not sure whether they are offering this program in Bangalore. Please visit their...
Raja
0 0
5

Now ask question in any of the 1000+ Categories, and get Answers from Tutors and Trainers on UrbanPro.com

Ask a Question

Related Lessons

ClassNotFoundException vs NoClassDefFoundError
ClassNotFoundException NoClassDefFoundError It is an exception and happens due to programmer’s mistake and can be recovered by updating the code. Thrown when an application tries...

Class, Object and Methods in JAVA
Lesson-1: Class, Object and Methods of Java can be compared with body, heart and brain. Without these 3 things, Java does not exist. If you Google the above 3 items, you will find many definitions. But...

Basic Concepts of Web Designing
An introduction to domain names, web servers, and website hosting 1)What is the web? In a nutshell, the web is a whole bunch of interconnected computers talking to one another. The computers (on the...

Java: A Quick Overview
Not purely Object Oriented: It doesn't support multiple inheritence, it supports primitive data types and static members. Doesn’t support multiple inheritance: Reason is diamond problem i.e.,...

How 4 byte float can store 8 byte long values in java ?
long l = 12464545L; float f = l; (fine) int i = l ; (Error) if we see the how this magic happens as we know the answer lies in the floating point representation as in floating points values does not...

Recommended Articles

Before we start on the importance of learning JavaScript, let’s start with a short introduction on the topic. JavaScript is the most popular programming language in the world, precisely it is the language - for Computers, the Web, Servers, Smart Phone, Laptops, Mobiles, Tablets and more. And if you are a beginner or planning...

Read full article >

Java is the most commonly used popular programming language for the creation of web applications and platform today. Integrated Cloud Applications and Platform Services Oracle says, “Java developers worldwide has over 9 million and runs approximately 3 billion mobile phones”.  Right from its first implication as java 1.0...

Read full article >

Designed in a flexible and user-friendly demeanor, Java is the most commonly used programming language for the creation of web applications and platform. It allows developers to “write once, run anywhere” (WORA). It is general-purpose, a high-level programming language developed by Sun Microsystem. Initially known as an...

Read full article >

In the domain of Information Technology, there is always a lot to learn and implement. However, some technologies have a relatively higher demand than the rest of the others. So here are some popular IT courses for the present and upcoming future: Cloud Computing Cloud Computing is a computing technique which is used...

Read full article >

Looking for Java Training Classes?

Learn from the Best Tutors on UrbanPro

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you
X

Looking for Java Training Classes?

The best tutors for Java Training Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn Java Training with the Best Tutors

The best Tutors for Java Training Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more