what is the use of declaring constructor as private?

Answer Posted / ranganathkini

By making all the constructors of a class private, you can
also prevent other class from extending the class without
marking the class final.

Is This Answer Correct ?    9 Yes 6 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

what is singleton class in java?

615


Draw a UML class diagram for the code fragment given below: public class StringApplet extends Applet { private Label sampleString; private Button showTheString; private ButtonHandler bHandler; private FlowLayout layout; public StringApplet() { sampleString = new Label(" "); showTheString = new Button (" Show the String"); bHandler = new ButtonHandler(); layout = new FlowLayout(); showTheString.addActionListener(bHandler); setLayout(layout); add(sampleString); add(showTheString); } class ButtonHandler implements ActionListener { public void actionPerformed(ActionEvent e) { samplestring.setText("Good Morning"); } } } Note: The methods need not be indicated on the diagram.

1577


What is the unit of plancks constant?

561


How do you sort a string in java?

532


Why singleton pattern is better than creating singleton class with static instance?

528






How the metacharacters are different from the ordinary characters?

560


What are the object and class classes used for?

548


Can a singleton class be inherited?

516


What is arrays fill in java?

539


Can you add null to a list java?

576


How many types of methods are there in java?

520


Why are arrays useful in java?

540


How do you add an element to a set in java?

492


What is extension method in java?

557


Justify your answer that you can't define a method inside another method in java, if you can then how?

597