{"id":484,"date":"2019-08-20T20:26:50","date_gmt":"2019-08-20T14:41:50","guid":{"rendered":"https:\/\/bcisnotes.com\/secondsemester\/?p=484"},"modified":"2020-05-05T13:51:57","modified_gmt":"2020-05-05T08:06:57","slug":"method-and-instance-variables","status":"publish","type":"post","link":"https:\/\/bcisnotes.com\/secondsemester\/object-oriented-programming\/method-and-instance-variables\/","title":{"rendered":"Method and Instance Variables || Classes and Objects || Bcis Notes"},"content":{"rendered":"<h1 style=\"text-align: center;\">Method and Instance Variables<\/h1>\n<p>Method and Instance Variables are described such as Methods are a collection of statements that are group together to operate. Method and Instance Variables are described below:<\/p>\n<h2>a.Method<\/h2>\n<p>Methods are used in Java to describe the behavior of an object. Methods are a collection of statements that are group together to operate. In Java, it is possible to create methods that have the same name, but different argument lists in various definitions, i.e., method overloading is possible in Java, which is one of the unique features of Object-Oriented Programming (OOP). In this chapter, we will learn about how method overloading is written and how it helps us within a Java program.<\/p>\n<p>A\u00a0method\u00a0is the equivalent of a function in\u00a0object-oriented programming. A noun is to a verb what a variable is to a method \u2014 the methods are the actions that perform operations on a variable. A method accepts parameters as arguments, manipulates these, and then produces an output when the method is called on an\u00a0object. Methods are similar to functions, but methods are also classified according to their purpose in the\u00a0class\u00a0design. In classes, variables are called\u00a0attributes, so methods often operate on attributes.<\/p>\n<h2><strong>What is Method Overloading?<\/strong><\/h2>\n<p>If a class of a Java program has a plural number of methods, and all of them have the same name but different parameters (with a change in type or number of arguments), and programmers can use them to perform a similar form of functions, then it is known as method overloading. If programmers what to perform one operation, having the same name, the method increases the readability of the program.<\/p>\n<p>Let us take an example where you can perform multiplication of given numbers, but there can be any number of arguments a user can put to multiply, i.e., from the user point of view the user can multiply two numbers or three numbers or four numbers or so on. If you write the method such as multi(int, int) with two parameters for multiplying two values, multi(int, int, int), with three parameters for multiplying three values and so on. A programmer does method overloading to figure out the program quickly and efficiently. Method Overloading is applied in a program when objects are required to perform similar tasks but different input parameters. Every time an object calls a method, Java matches up to the method name first and then the number and type of parameters to decide what definitions to execute. This process of assigning multiple tasks to the same method is known as Polymorphism. There are different ways to overload a method in Java. They are:<\/p>\n<ul>\n<li>Based on the number of parameters: In this case, the entire overloading concept depends on the number of parameters that are placed within the parenthesis of the method.<\/li>\n<li>Based on the data type of the parameter: With the arrangement of data type, within the parameter, overloading of the method can take place.<\/li>\n<li>Based on the sequence of data types in parameters: The method overloading also depends on the ordering of data types of parameters within the method.<\/li>\n<\/ul>\n<p>To create overloaded methods, programmers need to develop several different method definitions in the class, all have the same name, but the parameters list is different. Here is a sample code snippet:<\/p>\n<h2><strong>\u00a0b. Instance variables:-<\/strong><\/h2>\n<p>The instance variable in java is used by Objects to store their states. Variables that are defined without the STATIC keyword and are Outside any method declaration are Object-specific and are known as instance variables. They are called so because their values are instance specific and are not shared among instances.<\/p>\n<p>Variables defined inside methods, constructors, or blocks are called local variables. The variable will be declared and initialized within the method and it will be destroyed when the method has completed. Instance variables are variables within a class but outside any method.<\/p>\n<p>You may also like <a href=\"https:\/\/bcisnotes.com\/secondsemester\/operator-precedence\/\">operator precedence<\/a><\/p>\n<div class=\"ujugf69faba1ad7d5d\" ><div id=\"amzn-assoc-ad-668fe681-bdc6-49ee-a9f9-a4c2f5be29a0\"><\/div><script async src=\"\/\/z-na.amazon-adsystem.com\/widgets\/onejs?MarketPlace=US&adInstanceId=668fe681-bdc6-49ee-a9f9-a4c2f5be29a0\"><\/script><\/div><style type=\"text\/css\">\r\n@media screen and (min-width: 1201px) {\r\n.ujugf69faba1ad7d5d {\r\ndisplay: block;\r\n}\r\n}\r\n@media screen and (min-width: 993px) and (max-width: 1200px) {\r\n.ujugf69faba1ad7d5d {\r\ndisplay: block;\r\n}\r\n}\r\n@media screen and (min-width: 769px) and (max-width: 992px) {\r\n.ujugf69faba1ad7d5d {\r\ndisplay: block;\r\n}\r\n}\r\n@media screen and (min-width: 768px) and (max-width: 768px) {\r\n.ujugf69faba1ad7d5d {\r\ndisplay: block;\r\n}\r\n}\r\n@media screen and (max-width: 767px) {\r\n.ujugf69faba1ad7d5d {\r\ndisplay: block;\r\n}\r\n}\r\n<\/style>\r\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>Method and Instance Variables Method and Instance Variables are described such as Methods are a collection of statements that are group together to operate. Method <a class=\"mh-excerpt-more\" href=\"https:\/\/bcisnotes.com\/secondsemester\/object-oriented-programming\/method-and-instance-variables\/\" title=\"Method and Instance Variables || Classes and Objects || Bcis Notes\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":6,"featured_media":849,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v23.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Method and Instance Variables || Classes and Objects || Bcis Notes<\/title>\n<meta name=\"description\" content=\"Method and Instance Variables are described such as Methods are a collection of statements that are group together to operate.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/bcisnotes.com\/secondsemester\/object-oriented-programming\/method-and-instance-variables\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Method and Instance Variables || Classes and Objects || Bcis Notes\" \/>\n<meta property=\"og:description\" content=\"Method and Instance Variables are described such as Methods are a collection of statements that are group together to operate.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/bcisnotes.com\/secondsemester\/object-oriented-programming\/method-and-instance-variables\/\" \/>\n<meta property=\"og:site_name\" content=\"BCIS NOTES\" \/>\n<meta property=\"article:published_time\" content=\"2019-08-20T14:41:50+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-05-05T08:06:57+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/bcisnotes.com\/secondsemester\/wp-content\/uploads\/2019\/08\/methodninstance.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"340\" \/>\n\t<meta property=\"og:image:height\" content=\"230\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Octopus\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Octopus\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/bcisnotes.com\/secondsemester\/object-oriented-programming\/method-and-instance-variables\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/bcisnotes.com\/secondsemester\/object-oriented-programming\/method-and-instance-variables\/\"},\"author\":{\"name\":\"Octopus\",\"@id\":\"https:\/\/bcisnotes.com\/secondsemester\/#\/schema\/person\/1e7cf3abcf4849e9d66fc9f6b67ee861\"},\"headline\":\"Method and Instance Variables || Classes and Objects || Bcis Notes\",\"datePublished\":\"2019-08-20T14:41:50+00:00\",\"dateModified\":\"2020-05-05T08:06:57+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/bcisnotes.com\/secondsemester\/object-oriented-programming\/method-and-instance-variables\/\"},\"wordCount\":667,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/bcisnotes.com\/secondsemester\/#organization\"},\"image\":{\"@id\":\"https:\/\/bcisnotes.com\/secondsemester\/object-oriented-programming\/method-and-instance-variables\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/bcisnotes.com\/secondsemester\/wp-content\/uploads\/2019\/08\/methodninstance.jpg\",\"articleSection\":[\"Object Oriented Programming\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/bcisnotes.com\/secondsemester\/object-oriented-programming\/method-and-instance-variables\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/bcisnotes.com\/secondsemester\/object-oriented-programming\/method-and-instance-variables\/\",\"url\":\"https:\/\/bcisnotes.com\/secondsemester\/object-oriented-programming\/method-and-instance-variables\/\",\"name\":\"Method and Instance Variables || Classes and Objects || Bcis Notes\",\"isPartOf\":{\"@id\":\"https:\/\/bcisnotes.com\/secondsemester\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/bcisnotes.com\/secondsemester\/object-oriented-programming\/method-and-instance-variables\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/bcisnotes.com\/secondsemester\/object-oriented-programming\/method-and-instance-variables\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/bcisnotes.com\/secondsemester\/wp-content\/uploads\/2019\/08\/methodninstance.jpg\",\"datePublished\":\"2019-08-20T14:41:50+00:00\",\"dateModified\":\"2020-05-05T08:06:57+00:00\",\"description\":\"Method and Instance Variables are described such as Methods are a collection of statements that are group together to operate.\",\"breadcrumb\":{\"@id\":\"https:\/\/bcisnotes.com\/secondsemester\/object-oriented-programming\/method-and-instance-variables\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/bcisnotes.com\/secondsemester\/object-oriented-programming\/method-and-instance-variables\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/bcisnotes.com\/secondsemester\/object-oriented-programming\/method-and-instance-variables\/#primaryimage\",\"url\":\"https:\/\/bcisnotes.com\/secondsemester\/wp-content\/uploads\/2019\/08\/methodninstance.jpg\",\"contentUrl\":\"https:\/\/bcisnotes.com\/secondsemester\/wp-content\/uploads\/2019\/08\/methodninstance.jpg\",\"width\":340,\"height\":230,\"caption\":\"Method and Instance Variables || Classes and Objects || Bcis Notes\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/bcisnotes.com\/secondsemester\/object-oriented-programming\/method-and-instance-variables\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/bcisnotes.com\/secondsemester\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Method and Instance Variables || Classes and Objects || Bcis Notes\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/bcisnotes.com\/secondsemester\/#website\",\"url\":\"https:\/\/bcisnotes.com\/secondsemester\/\",\"name\":\"BCIS NOTES\",\"description\":\"Second Semester\",\"publisher\":{\"@id\":\"https:\/\/bcisnotes.com\/secondsemester\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/bcisnotes.com\/secondsemester\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/bcisnotes.com\/secondsemester\/#organization\",\"name\":\"BCIS NOTES\",\"url\":\"https:\/\/bcisnotes.com\/secondsemester\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/bcisnotes.com\/secondsemester\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/bcisnotes.com\/secondsemester\/wp-content\/uploads\/2019\/12\/cropped-2.jpg\",\"contentUrl\":\"https:\/\/bcisnotes.com\/secondsemester\/wp-content\/uploads\/2019\/12\/cropped-2.jpg\",\"width\":300,\"height\":100,\"caption\":\"BCIS NOTES\"},\"image\":{\"@id\":\"https:\/\/bcisnotes.com\/secondsemester\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/bcisnotes.com\/secondsemester\/#\/schema\/person\/1e7cf3abcf4849e9d66fc9f6b67ee861\",\"name\":\"Octopus\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/bcisnotes.com\/secondsemester\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/e31a69c6a6d830dca58523a537833871?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/e31a69c6a6d830dca58523a537833871?s=96&d=mm&r=g\",\"caption\":\"Octopus\"},\"url\":\"https:\/\/bcisnotes.com\/secondsemester\/author\/sujan\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Method and Instance Variables || Classes and Objects || Bcis Notes","description":"Method and Instance Variables are described such as Methods are a collection of statements that are group together to operate.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/bcisnotes.com\/secondsemester\/object-oriented-programming\/method-and-instance-variables\/","og_locale":"en_US","og_type":"article","og_title":"Method and Instance Variables || Classes and Objects || Bcis Notes","og_description":"Method and Instance Variables are described such as Methods are a collection of statements that are group together to operate.","og_url":"https:\/\/bcisnotes.com\/secondsemester\/object-oriented-programming\/method-and-instance-variables\/","og_site_name":"BCIS NOTES","article_published_time":"2019-08-20T14:41:50+00:00","article_modified_time":"2020-05-05T08:06:57+00:00","og_image":[{"width":340,"height":230,"url":"https:\/\/bcisnotes.com\/secondsemester\/wp-content\/uploads\/2019\/08\/methodninstance.jpg","type":"image\/jpeg"}],"author":"Octopus","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Octopus","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/bcisnotes.com\/secondsemester\/object-oriented-programming\/method-and-instance-variables\/#article","isPartOf":{"@id":"https:\/\/bcisnotes.com\/secondsemester\/object-oriented-programming\/method-and-instance-variables\/"},"author":{"name":"Octopus","@id":"https:\/\/bcisnotes.com\/secondsemester\/#\/schema\/person\/1e7cf3abcf4849e9d66fc9f6b67ee861"},"headline":"Method and Instance Variables || Classes and Objects || Bcis Notes","datePublished":"2019-08-20T14:41:50+00:00","dateModified":"2020-05-05T08:06:57+00:00","mainEntityOfPage":{"@id":"https:\/\/bcisnotes.com\/secondsemester\/object-oriented-programming\/method-and-instance-variables\/"},"wordCount":667,"commentCount":0,"publisher":{"@id":"https:\/\/bcisnotes.com\/secondsemester\/#organization"},"image":{"@id":"https:\/\/bcisnotes.com\/secondsemester\/object-oriented-programming\/method-and-instance-variables\/#primaryimage"},"thumbnailUrl":"https:\/\/bcisnotes.com\/secondsemester\/wp-content\/uploads\/2019\/08\/methodninstance.jpg","articleSection":["Object Oriented Programming"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/bcisnotes.com\/secondsemester\/object-oriented-programming\/method-and-instance-variables\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/bcisnotes.com\/secondsemester\/object-oriented-programming\/method-and-instance-variables\/","url":"https:\/\/bcisnotes.com\/secondsemester\/object-oriented-programming\/method-and-instance-variables\/","name":"Method and Instance Variables || Classes and Objects || Bcis Notes","isPartOf":{"@id":"https:\/\/bcisnotes.com\/secondsemester\/#website"},"primaryImageOfPage":{"@id":"https:\/\/bcisnotes.com\/secondsemester\/object-oriented-programming\/method-and-instance-variables\/#primaryimage"},"image":{"@id":"https:\/\/bcisnotes.com\/secondsemester\/object-oriented-programming\/method-and-instance-variables\/#primaryimage"},"thumbnailUrl":"https:\/\/bcisnotes.com\/secondsemester\/wp-content\/uploads\/2019\/08\/methodninstance.jpg","datePublished":"2019-08-20T14:41:50+00:00","dateModified":"2020-05-05T08:06:57+00:00","description":"Method and Instance Variables are described such as Methods are a collection of statements that are group together to operate.","breadcrumb":{"@id":"https:\/\/bcisnotes.com\/secondsemester\/object-oriented-programming\/method-and-instance-variables\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/bcisnotes.com\/secondsemester\/object-oriented-programming\/method-and-instance-variables\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/bcisnotes.com\/secondsemester\/object-oriented-programming\/method-and-instance-variables\/#primaryimage","url":"https:\/\/bcisnotes.com\/secondsemester\/wp-content\/uploads\/2019\/08\/methodninstance.jpg","contentUrl":"https:\/\/bcisnotes.com\/secondsemester\/wp-content\/uploads\/2019\/08\/methodninstance.jpg","width":340,"height":230,"caption":"Method and Instance Variables || Classes and Objects || Bcis Notes"},{"@type":"BreadcrumbList","@id":"https:\/\/bcisnotes.com\/secondsemester\/object-oriented-programming\/method-and-instance-variables\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/bcisnotes.com\/secondsemester\/"},{"@type":"ListItem","position":2,"name":"Method and Instance Variables || Classes and Objects || Bcis Notes"}]},{"@type":"WebSite","@id":"https:\/\/bcisnotes.com\/secondsemester\/#website","url":"https:\/\/bcisnotes.com\/secondsemester\/","name":"BCIS NOTES","description":"Second Semester","publisher":{"@id":"https:\/\/bcisnotes.com\/secondsemester\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/bcisnotes.com\/secondsemester\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/bcisnotes.com\/secondsemester\/#organization","name":"BCIS NOTES","url":"https:\/\/bcisnotes.com\/secondsemester\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/bcisnotes.com\/secondsemester\/#\/schema\/logo\/image\/","url":"https:\/\/bcisnotes.com\/secondsemester\/wp-content\/uploads\/2019\/12\/cropped-2.jpg","contentUrl":"https:\/\/bcisnotes.com\/secondsemester\/wp-content\/uploads\/2019\/12\/cropped-2.jpg","width":300,"height":100,"caption":"BCIS NOTES"},"image":{"@id":"https:\/\/bcisnotes.com\/secondsemester\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/bcisnotes.com\/secondsemester\/#\/schema\/person\/1e7cf3abcf4849e9d66fc9f6b67ee861","name":"Octopus","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/bcisnotes.com\/secondsemester\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/e31a69c6a6d830dca58523a537833871?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e31a69c6a6d830dca58523a537833871?s=96&d=mm&r=g","caption":"Octopus"},"url":"https:\/\/bcisnotes.com\/secondsemester\/author\/sujan\/"}]}},"_links":{"self":[{"href":"https:\/\/bcisnotes.com\/secondsemester\/wp-json\/wp\/v2\/posts\/484"}],"collection":[{"href":"https:\/\/bcisnotes.com\/secondsemester\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bcisnotes.com\/secondsemester\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bcisnotes.com\/secondsemester\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/bcisnotes.com\/secondsemester\/wp-json\/wp\/v2\/comments?post=484"}],"version-history":[{"count":8,"href":"https:\/\/bcisnotes.com\/secondsemester\/wp-json\/wp\/v2\/posts\/484\/revisions"}],"predecessor-version":[{"id":1021,"href":"https:\/\/bcisnotes.com\/secondsemester\/wp-json\/wp\/v2\/posts\/484\/revisions\/1021"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/bcisnotes.com\/secondsemester\/wp-json\/wp\/v2\/media\/849"}],"wp:attachment":[{"href":"https:\/\/bcisnotes.com\/secondsemester\/wp-json\/wp\/v2\/media?parent=484"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bcisnotes.com\/secondsemester\/wp-json\/wp\/v2\/categories?post=484"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bcisnotes.com\/secondsemester\/wp-json\/wp\/v2\/tags?post=484"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}