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 a constructor in Java?
Constructor is a special method to initialise Java objects. Usually initialisation logic is kept inside the constructor. Java compiler by default creates a default no arg constructor if no constructor is defined already.
Rishu
0 0
5
What is the general syllabus covered in core Java training from any institution?
you can check the syallbus on http://felix-its.com/java-training-pune/
Shiv Kohli
0 0
5
What is the best site to learn Java for development?
https://beginnersbook.com/java-tutorial-for-beginners-with-examples/ This is the best website for Java beginners.
Chai
0 0
8

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

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

Ask a Question

Related Lessons

Internet of Things, Social Media Becoming Part of E-Discovery Landscape
The days when e-discovery consisted of handing over copies of e-mails to address Freedom of Information Act (FOIA) requests, compliance regulations or other legal obligations are over. Now, it's just as...

JAVA - Object Cloning
JAVA - Object Cloning Is the way of creating the same copy of object without calling the class constructor. It means we can make any class object multiple times without calling its default constructor....

Mastering in Java Programming
Core java topics What is Java?Execution Model Of JavaBytecodeHow to Get Java?A First Java ProgramCompiling and Interpreting ApplicationsThe JDK Directory StructureUsing Eclipse Data types and Variables What...

Overview on Auto IT and use in selenium webdriver
AutoIt v3 is a freeware BASIC-like scripting languages designed for automating the windows GUI and general scripting. It used a combination of simulated keystrokes, mouse movements and window/control manipulation...
S

CoreJAVA
Core Java Training High Level Course Content Trained by Java Architect 1. Core Java Programming Introduction of Java 2. Data types and Operators 3. Control Flow statements 4. OOPS and its application...
A

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