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 |
How can final class be used?
What is visibility mode?
Hi Friends, I am beginner in java. what i know about synchonized keyword is,If more that one 1 thread tries to access a particular resource we can lock the method using synchronized keyword. Then after that how the lock is released and how next thread access that.Please explain with example.
how to create multithreaded program? Explain different ways of using thread? When a thread is created and started, what is its initial state? : Java thread
Does collectionutils isempty check for null?
What is the purpose of a parameter?
how to run ecllipse with jettyserver for windows environment using batch file
Differentiate between overriding and overloading cases?
How many bits is a 64 bit byte?
What is a vector in java?
Why do we need variables?
what is the difference between Java Command Line and C command Line?