How to create an instance of a class without using "new"
operator? Plz help me out properly.Thank u.
Answer Posted / b s vidyasagar reddy
three types
1.using factory methods
NumberFormat obj = NumberFormat.getNumberInstance();
2. using newInstance() method
class c = class.forName("Employee");
Employee obj = c.newInstance();
3. using coloning:
coloning is a way to create Bitwise exactcopy of an
existing object
Employee e2=e1.clone();
| Is This Answer Correct ? | 32 Yes | 4 No |
Post New Answer View All Answers
Is java call by value?
What is the use of static class?
Is string a wrapper class?
Is empty set an element of empty set?
How hashset works internally in java?
What is lastindexof in java?
Where will it be used?
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.
How do you create immutable object in java?
What is a boolean field?
What is the requirement of thread in java?
Can variables be used in java without initialization?
Can we serialize static variables in java?
What are the problems faced by java programmers who don't use layout managers?
What is the super void?