can we create object for static class in java
Answers were Sorted based on User's Feedback
Answer / usha
Hi all, If u want to create a static class then no need to
create instance for the class.If u create a instance then
there is no purpose to create that class as static.As in
case of static members & static methods , we are not
creating instance, just we are calling those by using class
name only.
Is This Answer Correct ? | 54 Yes | 6 No |
yes you can create an object of a static class.........
but there is no meaning ..........
because we used an static class when we dont want to create
an object.........
you can used these data members and methods without create
an object...........
otherwise u directly create an object without used the
static class ok
........
Thank You
Is This Answer Correct ? | 51 Yes | 11 No |
Answer / sandeep
an outer class cannot be static.it can only be declared as
pubic,abstract or final OR a combination..
an inner static class behaves just like a normal static member..
n yes v can creat an object of inner static class as....
Outer.Inner obj=new Outer.Inner();
Is This Answer Correct ? | 38 Yes | 4 No |
Answer / sriragv
There is no need to instantiate the object to make a copy
of the class in your system because already there is a copy
of the class will be available in the JVM we can directly
access them by 'class.member'
Is This Answer Correct ? | 10 Yes | 3 No |
Answer / ashlesha sharma
there are two types of classes..
1.Top level class
2.inner class
top level classes cant be declared as static.Its a
compilation error.
inner classes can be declared as follows:
1.Anonymous classes: cant be declared as static.
2.Local classes: cant be declared as static.
3.member classes: the only class that can be declared as static.
4.nested loop level class:A nested top-level class is a
member classes with a static modifier. A nested top-level
class is just like any other top-level class except that it
is declared within another class or interface.
Is This Answer Correct ? | 4 Yes | 1 No |
Answer / shishir
for a top level class a static but you can create a inner
class static and make an object of same, but it will be of
no use as static class you can use with out instantiating.
Is This Answer Correct ? | 3 Yes | 1 No |
Answer / surendra pokuri
we cann't code static outer class.
we can define static nested class.
so we can create instance of static nested class, but no
need to create.
we can use directly
as
outerclass.innercla.
Is This Answer Correct ? | 4 Yes | 2 No |
Answer / goldy
When you have to access any member of a class, you have to
create an instance of the class
Ex:- class NewClass
{
int member1;
int member2(){ }
}
create an instance
of the "NewClass" class in any class you want to
access the members.
ex:
class OtherClass{
member1;
member2; ....
OtherClass instanceOfOtherClass= new NewClass();
// instanceOfOtherClass ---> is object
}
if you declare a class as static there is no need to
create the instance ( so called object)
you can directly call the members by
class name
if NewClass were static
"NewClass.member1;"
is it clear
Is This Answer Correct ? | 15 Yes | 15 No |
Answer / munna
hi all, yes we can create but the static members are common
for all the objects.
Is This Answer Correct ? | 1 Yes | 1 No |
What is a treeset in java?
why pointer is not used in java?
How do you make a thread in java?
Can we make constructors static?
Definition for connection pooling?
Have you used any version control ? if so explain about it?
Can we iterate through collection using for loop?
what is main purpose of interface?
2 Answers Accenture, HCL, NIIT,
if am have 100 threads(for ex:T1,T2---T100) how we give priority to these threads and how the system excute these threads
How do you find the independent variable?
what is optional in java 8?
What error occurs if a try-catch-finally statement sequence does not have a catch clause?