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

How to prepare for CORE JAVA for Android Developement?

Core Java is required for basic understanding of inheritance , AWT with button action programs, library usage etc then after u can genrate your logic with additional topics of Android
Rishabh
0 0
6
What is serialization?
serialization is a storing the state of the object into the file
Shubham
Which language has the best future prospects: Python, Java, or JavaScript?
According to me, "Python" is the programming language having the best future prospect considering the current industry trend. Reason: Python is extensively used in advanced technologies such as Machine...
Atharva
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

Constructor Overloading
public class ConstructorOverloading { public ConstructorOverloading(){ System.out.println("default"); } public ConstructorOverloading(String a){ System.out.println("a"); } public ConstructorOverloading(int...
S

Sarthak C.

0 0
0

Big Data Hadoop Training
What is Big Data? Big data means really a big data, it is a collection of large datasets that cannot be processed using traditional computing techniques. Big data is not merely a data, rather it has become...

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...

Thread Class In JAVA
Thread Class: Thread class is the main class on which Java's Multithreading system is based. Thread class, along with its companion interface Runnable will be used to create and run threads for utilizing...

Java Overview
Java platform overview Java platform components The Java platform consists of the following components. The Java language Like any programming language, the Java language has its own structure, syntax...
A

Akshay Shende

0 0
0

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