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 |
Can multiple catch statements be used in exceptions ?
Why java is free from garbage values??
What is an object's lock and which object's have locks in java programming?
Where can i get Latest SUN Certification Dumps and what are the Sun Certification Codes that are available, Im new to JAVA, so please gimme info as i need to write J2EE - Core Java Certification
explain the concept of inheritance with an example?
What is a parameter in simple terms?
In how many ways we can the thread? in java
How to synchonise HashMap
How do you compare arrays in java?
What is a generic code?
What are predefined functions?
List some features of the abstract class.