Classes And Objects Creation - LearnHowToCode SarkariResult.com Interview Questions and Answers LearnHowToCodeOnline
Classes And Objects Write a Program

Classes And Objects Creation

Classes And Object

A class is a model for creating object.This means the properties and action of the object arewritten in the class. Properties are represented  by variable and action of the object
are represent by methods. So class a contains variables and mehtods.


If we take a person classes . we can write code in the class that specifies the properties and
action performed by any person. For example ......
     A person has properties like name, age, etc. Similarly, a person can perform an action like
   talking, walking. etc. So the class Dog contains these properties and action shows here
class Dog

{
// properties - instance variable

        String name="tiger";
         int age=12;
         // action -methods
    void talk(){

     System.out.println("hello Iam "+name);

     System.out.println("MY age Is "+age);}

}
class MainClass
{
public static  void main (String[]args)
{
    Dog d=new Dog();
     d.talk();
  }
}

Object Creation 

we know that the class code along with method code is stored in method area of the JVM .
when an object is created. the memory is allocated on "Heap"ofter creation of an object
JVM produces unique reference number for the object from the memory address of the object.
This is reference number is also called hash code number. Ex...................

hash code number and reference of an object

Employee e1=new Employee();// e1 is reference of employee object
System.out.println(e1.hashCode());// display hash code stored in e1.




About EasyToCode

I'm Ethan Mariano a software engineer by profession and reader/writter by passion.I have good understanding and knowledge of AngularJS, Database, javascript, web development, digital marketing and exploring other technologies related to Software development.

0 comments:

Featured post

Political Full Forms List

Acronym Full Form MLA Member of Legislative Assembly RSS Really Simple Syndication, Rashtriya Swayamsevak Sangh UNESCO United Nations E...

Powered by Blogger.