what is the difference between static class and singleton class? can we create static class?
Answers were Sorted based on User's Feedback
Static class always a inner class. and static class can create multiple objects.all object have different reference value.
But on the other hand SingleTon class can have only single object because every object reference variable have same reference value.
Is This Answer Correct ? | 3 Yes | 0 No |
Answer / pratima thakur
1.We can create static class object like the below example.
class OuterClass
{
void outerMethod()
{
System.out.println("Inside in outerclass");
}
static class InnerClass
{
void innerMethod()
{
System.out.println("Inside in innerclass");
}
}
public static void main(String args[])
{
InnerClass iclass=new InnerClass();
InnerClass iclass1=new InnerClass();
iclass.innerMethod();
}
}
2.Single tone class implementaion
public class MySingleTon {
private static MySingleTon myObj;
/**
* Create private constructor
*/
MySingleTon(){
}
/**
* Create a static method to get instance.
*/
public static MySingleTon getInstance(){
if(myObj == null){
myObj = new MySingleTon();
}
return myObj;
}
public void getSomeThing(){
// do something here
System.out.println("I am here....");
}
public static void main(String a[]){
MySingleTon st = MySingleTon.getInstance();
System.out.println(st);
MySingleTon st1 = MySingleTon.getInstance();
System.out.println(st1);
st.getSomeThing();
}
}
Is This Answer Correct ? | 1 Yes | 0 No |
What is lambda expression in java?
84. try { 85. ResourceConnection con = resourceFactory.getConnection(); 86. Results r = con.query(”GET INFO FROM CUSTOMER”); 87. info = r.getData(); 88. con.close(); 89. } catch (ResourceException re) { 90. errorLog.write(re.getMessage()); 91. } 92. return info; Which is true if a ResourceException is thrown on line 86? 1 Line 92 will not execute. 2 The connection will not be retrieved in line 85. 3 The resource connection will not be closed on line 88. 4 The enclosing method will throw an exception to its caller.
Define how can we find the actual size of an object on the heap?
What is parameter example?
What are the steps that are followed when two computers connect through tcp?
what is the major difference between linkedlist and arraylist in java?
Explain the pointers in Java?
write a code, we have two thread, one is printing even no and other print the odd no.
How can we find size of the object ?
What is an i/o filter?
How GC (Garbage Collector) knows the objects reference is unused.Whether GC removes the unused object Parmanently or it maintains something.
What is meant by vector class, dictionary class, hash table class, and property class?