{"id":2009,"date":"2017-05-14T06:30:54","date_gmt":"2017-05-14T06:30:54","guid":{"rendered":"https:\/\/www.testingdocs.com\/questions\/?p=2009"},"modified":"2021-03-21T07:33:16","modified_gmt":"2021-03-21T07:33:16","slug":"object-oriented-cylinder-class-demo","status":"publish","type":"post","link":"https:\/\/www.testingdocs.com\/questions\/object-oriented-cylinder-class-demo\/","title":{"rendered":"Cylinder class java program demo."},"content":{"rendered":"<p>In this post, we will create a Cylinder java class and a demo main program to calculate the volume of the cylinder.<\/p>\r\n<h3>Java Program<\/h3>\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">public class Cylinder {\r\n\r\n  private double height;\r\n  private double radius;\r\n\r\n  \/**\r\n   * @param height\r\n   * @param radius\r\n   *\/\r\n  public Cylinder(double height, double radius) {\r\n    this.height = height;\r\n    this.radius = radius;\r\n  }\r\n\r\n  \/**\r\n   * @return the height\r\n   *\/\r\n  public double getHeight() {\r\n    return height;\r\n  }\r\n\r\n  \/**\r\n   * @param height the height to set\r\n   *\/\r\n  public void setHeight(double height) {\r\n    this.height = height;\r\n  }\r\n\r\n  \/**\r\n   * @return the radius\r\n   *\/\r\n  public double getRadius() {\r\n    return radius;\r\n  }\r\n\r\n  \/**\r\n   * @param radius the radius to set\r\n   *\/\r\n  public void setRadius(double radius) {\r\n    this.radius = radius;\r\n  }\r\n\r\n  \/\/calculating Volume of the cylinder\r\n  public double calculateVolume() {\r\n    return Math.PI * radius * radius * height;\r\n  }\r\n}\r\n<\/pre>\r\n<h3>\u00a0<\/h3>\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">\/\/ Main class\r\npublic class CylinderMain {\r\n  public static void main(String args[]) {\r\n    \/\/ Creating two Cylinder objects\r\n    Cylinder c1 = new Cylinder(5.0,3.5);\r\n\r\n    Cylinder c2 = new Cylinder(15.0,5.5);\r\n\r\n    System.out.println(\"--------------Output----------\");\r\n    System.out.println(\"Height of C1 = \" + c1.getHeight());\r\n    System.out.println(\"Radius of C1 = \" + c1.getRadius());\r\n    System.out.println(\"Volume of C1 = \" + c1.calculateVolume());\r\n\r\n    \r\n    System.out.println(\"Height of C2 = \" + c2.getHeight());\r\n    System.out.println(\"Radius of C2 = \" + c2.getRadius());\r\n    System.out.println(\"Volume of C2 = \" + c2.calculateVolume());\r\n\r\n  }\r\n}\r\n<\/pre>\r\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2011 size-full\" src=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Two-Cylinder-objects-.png\" alt=\"\" width=\"1684\" height=\"863\" title=\"\" srcset=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Two-Cylinder-objects-.png 1684w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Two-Cylinder-objects--300x154.png 300w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Two-Cylinder-objects--1024x525.png 1024w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Two-Cylinder-objects--768x394.png 768w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Two-Cylinder-objects--1536x787.png 1536w\" sizes=\"auto, (max-width: 1684px) 100vw, 1684px\" \/><\/p>\r\n<h3>\u00a0<\/h3>\r\n<h3>Code Screenshot<\/h3>\r\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-2010 size-full\" src=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Cylinder-class.png\" alt=\"\" width=\"1743\" height=\"922\" title=\"\" srcset=\"https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Cylinder-class.png 1743w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Cylinder-class-300x159.png 300w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Cylinder-class-1024x542.png 1024w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Cylinder-class-768x406.png 768w, https:\/\/www.testingdocs.com\/questions\/wp-content\/uploads\/Cylinder-class-1536x813.png 1536w\" sizes=\"auto, (max-width: 1743px) 100vw, 1743px\" \/><\/p>\r\n<h3>Output<\/h3>\r\n<p>&#8212;&#8212;&#8212;&#8212;&#8211;Output&#8212;&#8212;&#8212;-<br \/>Height of C1 = 5.0<br \/>Radius of C1 = 3.5<br \/>Volume of C1 = 192.42255003237483<br \/>Height of C2 = 15.0<br \/>Radius of C2 = 5.5<br \/>Volume of C2 = 1425.4976665663685<\/p>\r\n<!--themify_builder_content-->\n<div id=\"themify_builder_content-2009\" data-postid=\"2009\" class=\"themify_builder_content themify_builder_content-2009 themify_builder tf_clear\">\n    <\/div>\n<!--\/themify_builder_content-->\n","protected":false},"excerpt":{"rendered":"<p>In this post, we will create a Cylinder java class and a demo main program to calculate the volume of the cylinder. Java Program public class Cylinder { private double height; private double radius; \/** * @param height * @param radius *\/ public Cylinder(double height, double radius) { this.height = height; this.radius = radius; } [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[18],"tags":[],"class_list":["post-2009","post","type-post","status-publish","format-standard","hentry","category-java-programs","has-post-title","has-post-date","has-post-category","has-post-tag","has-post-comment","has-post-author",""],"_links":{"self":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/2009","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/comments?post=2009"}],"version-history":[{"count":3,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/2009\/revisions"}],"predecessor-version":[{"id":19769,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/posts\/2009\/revisions\/19769"}],"wp:attachment":[{"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/media?parent=2009"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/categories?post=2009"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.testingdocs.com\/questions\/wp-json\/wp\/v2\/tags?post=2009"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}