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 |
write a program to create an arraylist with string(add,remove) operation.and value should be enter through keyboard.
I have a string like _a01_a02_a03_ and another string like _2_1.5_4_ as input.I want to extract a01,a02... to a string array and 2,1.5,etc to a double array with a01 corresponds to 2 and a02 to 1.5 etc. Need code in core java.. Can you do it?
What are the methods available in a class?
Explain java heap space and garbage collection?
What does sprintf mean?
Discuss about garbage collector in Java.
0 Answers Agilent, Integreon, ZS Associates,
what is the use of abstract class?
3 Answers Amdocs, Atos Origin, Invictus,
How many types of constructors are used in java?
What is the purpose of the finally clause of a try-catch-finally statement in java programming?
Name the package that most of the AWT events that supports event-delegation model are defined?
Why should I use abstract class?
what is a working thread? : Java thread