1. Can we declare and use a private constructor in any class?
2. Can we use return statement between two statements of a method in Java?
3. Can we create the object of a local class in any other class? How?
4. Can we override a static method?
5. How can you find the address of an ArrayList object in Java?
2. Can we use return statement between two statements of a method in Java?
3. Can we create the object of a local class in any other class? How?
4. Can we override a static method?
5. How can you find the address of an ArrayList object in Java?
1.yes,in case we have two or more overloaded constructors to make object for that class.
ReplyDeletealso in case if we dont have only static members n main function is in the same class we can declare its constuctor as private, as we will not need to create its object.
also we can use inhertance.
class B
{
B()
{
System.out.println("B constructor is called");
}
}
class A extends B
{
int a;
private A()
{
int a=0;
System.out.println("A constructor is called");
}
public static A fun()
{
A obj=new A();
return obj;
}
public void yahoo()
{
System.out.println("A method of class A is called");
}
}
public class C
{
public static void main(String []args)
{
B obj1=A.fun();
}
}
..
Although we cannot use others methods .. eg- yahoo() here.
...
Correct ...
Delete