Creating an object in Java

First, we need to allocate some memory for the object in the class. Memory can be allocated with the help of the new operator followed by the class name. Then we define an object name for it. The return type should always be the class name. This is the syntax for creating a memory allocation for a class. So the code for memory allocation for the preceding example will look something like the following:

Firstclass fn=new Firstclass();

Here, we say fn is the object of the Firstclass class. Now that we have created an object, let's see how we can access it.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.251.154