what is an object and how do you allocate memory to it?
Answer Posted / tulasi
Object is an instance of the class.There are two ways by
which a new object is created.
1.using new operator.
example:
classname objectname=new classname;
This allocates the memory to objectname.
This can be classname objectname by which null values are
set to the objectname and not the values as in the class.
2.without using new operator.
Declare the variables as static and also methods used as
static and by using the keyword static we can create an
instance of the class.
Thus, we use public static void main(String args[])in main
program where theres no need to create a class and also
instance of class using new operator.
| Is This Answer Correct ? | 8 Yes | 3 No |
Post New Answer View All Answers
Why is a string immutable?
Can we have any other return type than void for main method?
What is the meaning of flag day?
Explain the purpose of garbage collection in Java?
What is foreach loop in java?
Explain about core java?
Difference between nested and inner classes ?
What is oops in java?
Can we execute a program without main() method?
Explain the importance of import keyword in java?
Can a method be static?
What is the purpose of interface?
Is java good for beginners?
What is the Difference between Final Class && Abstract Class?
how to deploy apache tomcat server to weblogic server in java