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 |
Explain the difference between comparator and comparable in java?
we have two threads..both the threads are reading the data.. is there any need of synchronization there?...justify it?
What is an enumeration class?
What for read() function?
What is use of inner class in java?
Create a form of user Login in JSP, that accepts the user name and password from user and authenticate it with user names and passwords stored in database. (Plz provide me answer immediately)
What do you mean by exception handling in Java?
does java support pointers?
What is the difference between yielding and sleeping in java programming?
Explain about doubly linked list
0 Answers Aditi Placement Service,
What is anagram number?
What language is pass by reference?