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 working with a reputed Institute. Headquarters: Hyderabad

No, private constructor creation is not possible.
Comments

Master

Yes possible, but only within the class in which private contructor is written
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

Computer

YES WE CAN CREATE OBJECT FOR THAT CLASS WITH IN THE SAME CLASS. OUT SIDE OF THE CLASS IT IS NOT POSSIBLE. Example:- Step 1 you have to declare static variable Step 2 private construct . Step 3 access the object with static method Just like Class.forName(); public class SingleTonClass { ...
read more
YES WE CAN CREATE OBJECT FOR THAT CLASS WITH IN THE SAME CLASS. OUT SIDE OF THE CLASS IT IS NOT POSSIBLE. Example:- Step 1 you have to declare static variable Step 2 private construct . Step 3 access the object with static method Just like Class.forName(); public class SingleTonClass { //Static Class Reference private static SingleTonClass obj=null; private SampleSingleTonClass(){ } public static SingleTonClass objectCreationMethod(){ /*This logic will ensure that no more than * one object can be created at a time */ if(obj==null){ obj= new SingleTonClass(); } return obj; } public void display(){ System.out.println("Singleton class Example"); } public static void main(String args[]){ //Object cannot be created directly due to private constructor //This way it is forced to create object via our method where //we have logic for only one object creation SingleTonClass myobject= SingleTonClass.objectCreationMethod(); myobject.display(); } } read less
Comments

Software Engineer

yes via singlton pattern
Comments

Tutor taking Computer subjects Classes

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

Trainer

If you declare a constructor as private, only code within the class itself can instantiate an object. The common cases of using the private constructors are Classes with only static methods Classes with only constants When implementing singleton pattern Enums
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

View 15 more Answers

Related Questions

What is JavaBean?
All javabeans are pojos ,But not all pojos are not javabeans.
Ankit
0 0
6
When we are used the compiler and interpreter? what is the difference between them?
Java code is the best example of compiled as well as interpreted. Java Compiler does the task of compiling . Java file to .class file(binary form). JVM works as interpreter to let Operating system understand the compiled code instructions.
Shilpa
in java every thing is in the form of object
Everything is object is java except primitive data types like int,long etc..thats the reason its not 100 % object oriented language..
Abrar
Is there any difference between Serializalble and Externalizable interface?
1. In case of Serializable, default serialization process is used. while in case of Externalizable custom Serialization process is used which is implemented by application. 2. JVM gives call back...
Vathsala

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

Ask a Question

Related Lessons

Java8 Filters and collectors
Lets say we have collection of strings and we would like to filter (remove) out certain strings from collection. We could achive the same in java 7 and earlier versions import java.util.ArrayList; import...

Observer Pattern in Java.
As I was going through the different source code files of the Java Util package, I found the implementation of the Observer Pattern ( see the Gang of Four books for more information on this pattern) in...

Java inheritance example
Answer these questions Answer the above question

A Tip for the beginners.
The world of programming languages right now is too dense, and too big for any beginner. But at the same time, because of so many options available, it's easier too. You can start with any language that...

Crux Of The Basic Interview Question Asked Around It Professionals
Question: Explain PSVM() in Java. Answer: This question is asked from a differnet persctive. Person asking this question is looking for deep java concepts. If answer in your mind is something like...

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