{"id":89,"date":"2023-05-04T12:55:50","date_gmt":"2023-05-04T10:55:50","guid":{"rendered":"http:\/\/oopm.org\/?page_id=89"},"modified":"2024-11-29T11:54:43","modified_gmt":"2024-11-29T10:54:43","slug":"a1-objects-and-classes-in-java","status":"publish","type":"page","link":"https:\/\/oopm.org\/?page_id=89","title":{"rendered":"3.x.1 Objects and classes in Java"},"content":{"rendered":"<div class=\"pdfprnt-buttons pdfprnt-buttons-page pdfprnt-top-right\"><a href=\"https:\/\/oopm.org\/index.php?rest_route=wpv2pages89&print=pdf\" class=\"pdfprnt-button pdfprnt-button-pdf\" target=\"_blank\"><img decoding=\"async\" src=\"https:\/\/oopm.org\/wp-content\/plugins\/pdf-print\/images\/pdf.png\" alt=\"image_pdf\" title=\"View PDF\" \/><\/a><a href=\"https:\/\/oopm.org\/index.php?rest_route=wpv2pages89&print=print\" class=\"pdfprnt-button pdfprnt-button-print\" target=\"_blank\"><img decoding=\"async\" src=\"https:\/\/oopm.org\/wp-content\/plugins\/pdf-print\/images\/print.png\" alt=\"image_print\" title=\"Print Content\" \/><\/a><\/div>\n<p class=\"wp-block-paragraph\">As mentioned, Java, does not have good support for singular objects as described in chapter 2. In most cases, objects are instances of classes so to create objects like&nbsp;<code>Account_1010<\/code> representing the account of John Smith,&nbsp;we use class&nbsp;<code>Account,<\/code>&nbsp;which may be defined as follows:<\/p>\n\n\n\n<pre class=\"wp-block-code has-primary-color has-text-color\"><code><code><span style=\"font-family: inherit; font-size: inherit; color: var(--wp--preset--color--primary);\"><strong>class<\/strong> Account {<\/span><\/code>   Account(Customer ow) {\n      owner = ow; \n   }\n   Customer owner;\n   float balance;\n   float interestRate;\n   addInterest() {\n      balance = balance + (balance * interestRate) \/ 100;\n   }\n   deposit(float amount) {\n      balance = balance + amount;\n   }\n   float withdraw(float amount) {\n      balance  = balance - amount;\n      return balance;\n}<\/code><\/pre>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background has-tiny-font-size wp-block-paragraph\">Explain class Account, the constructor, introduce main and show how to create instances.<br>Show class Customer.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>final<\/strong> Account account_1010 = <strong>new<\/strong> Account(JohnSmithsProfile)<\/code><\/pre>\n\n\n\n<p class=\"has-pale-cyan-blue-background-color has-background has-tiny-font-size wp-block-paragraph\">Class Customer, JohnSmithsProfile, references, etc.<\/p>\n<div style=\"display:flex; gap:10px;justify-content:center\" class=\"wps-pgfw-pdf-generate-icon__wrapper-frontend\">\n\t\t<a  href=\"https:\/\/oopm.org?action=genpdf&amp;id=89\" class=\"pgfw-single-pdf-download-button\" ><img src=\"https:\/\/oopm.org\/wp-content\/plugins\/pdf-generator-for-wp\/admin\/src\/images\/PDF_Tray.svg\" title=\"Generate PDF\" style=\"width:auto; height:45px;\"><\/a>\n\t\t<\/div>","protected":false},"excerpt":{"rendered":"<p>As mentioned, Java, does not have good support for singular objects as described in chapter 2. In most cases, objects are instances of classes so to create objects like&nbsp;Account_1010 representing the account of John Smith,&nbsp;we use class&nbsp;Account,&nbsp;which may be defined as follows: Explain class Account, the constructor, introduce main and show how to create instances.Show [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":87,"menu_order":3,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-89","page","type-page","status-publish","hentry"],"mb":[],"mfb_rest_fields":["title","gutenberg_elementor_mode"],"_links":{"self":[{"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/89","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/oopm.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=89"}],"version-history":[{"count":17,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/89\/revisions"}],"predecessor-version":[{"id":9972,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/89\/revisions\/9972"}],"up":[{"embeddable":true,"href":"https:\/\/oopm.org\/index.php?rest_route=\/wp\/v2\/pages\/87"}],"wp:attachment":[{"href":"https:\/\/oopm.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=89"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}