can we create object for static class in java
Answer Posted / 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 |
Post New Answer View All Answers
What is lossy conversion in java?
Can two objects have same hashcode?
Why java is object oriented?
What are the different collection views provided by maps?
How many ways can an argument be passed to a subroutine and explain them?
What is nested interface?
What do you mean by default constructor in java?
What will be the initial value of an object reference which is defined as an instance variable?
Is java a security risk?
Explain a situation where finally block will not be executed?
How would overload a function based on return type?
What is an abstract class and what is it’s purpose?
Is zero a positive integer?
What are data structures in java?
Why are parameters used in functions?