{"id":9688,"date":"2022-01-17T07:29:16","date_gmt":"2022-01-17T07:29:16","guid":{"rendered":"https:\/\/prwatech.in\/blog\/?p=9688"},"modified":"2024-04-11T07:27:53","modified_gmt":"2024-04-11T07:27:53","slug":"scala-practicals-part-3","status":"publish","type":"post","link":"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-practicals-part-3\/","title":{"rendered":"SCALA- PRACTICALS PART 3"},"content":{"rendered":"<h2><span data-sheets-root=\"1\" data-sheets-value=\"{&quot;1&quot;:2,&quot;2&quot;:&quot;SCALA- PRACTICALS PART 3&quot;}\" data-sheets-userformat=\"{&quot;2&quot;:6145,&quot;3&quot;:{&quot;1&quot;:0,&quot;3&quot;:1},&quot;14&quot;:{&quot;1&quot;:3,&quot;3&quot;:1},&quot;15&quot;:&quot;Arial&quot;}\">SCALA- PRACTICALS PART 3<\/span><\/h2>\n<p>&nbsp;<\/p>\n<p><b><span data-contrast=\"auto\">Question:<\/span><\/b><span data-contrast=\"auto\"> Calculate area of hall for 5 flats in a floor.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559685&quot;:360,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p><b><span data-contrast=\"auto\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Solution:<\/span><\/b><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">Suppose we have A building with 9th floor. And we have to calculate the area of 5 flat whose dimension are given below\u00a0<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559685&quot;:360,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">A-901 length len= 40.96, Width wid =20.00<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559685&quot;:360,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">A-902 length len =35.84, Width wid =22.08<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559685&quot;:360,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">A-903 length len =30.08, Width wid =16.00<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559685&quot;:360,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">A-904 length len =45.50, Width wid =25.00<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559685&quot;:360,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">A-905 length len =45.30, Width wid = 23.35<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559685&quot;:360,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">Logic to find out the area of 5 flats of building whose dimensions are given: [len*wid]: logic<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559685&quot;:360,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><b><span data-contrast=\"auto\">Output:<\/span><\/b><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">819.2<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">788.48<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">480.0<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">1137.5<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">964.355<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">Process finished with exit code 0<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p>&nbsp;<\/p>\n<p><b><span data-contrast=\"auto\">Note:<\/span><\/b><span data-contrast=\"auto\"> without constructor, complier will never return any output\u00a0<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"3\" aria-setsize=\"-1\" data-aria-posinset=\"1\" data-aria-level=\"1\"><span data-contrast=\"auto\">Default constructor\u00a0<\/span><span data-ccp-props=\"{&quot;134233279&quot;:true,&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"3\" aria-setsize=\"-1\" data-aria-posinset=\"2\" data-aria-level=\"1\"><span data-contrast=\"auto\">Primary constructor\u00a0<\/span><span data-ccp-props=\"{&quot;134233279&quot;:true,&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"3\" aria-setsize=\"-1\" data-aria-posinset=\"3\" data-aria-level=\"1\"><span data-contrast=\"auto\">Auxiliary constructor\u00a0<\/span><span data-ccp-props=\"{&quot;134233279&quot;:true,&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/li>\n<\/ul>\n<p><b><span data-contrast=\"auto\">println is nothing it\u2019s a by default constructor.<\/span><\/b><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">constructor means it will print something.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p><b><span data-contrast=\"auto\">Step: of complier\u00a0<\/span><\/b><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"4\" aria-setsize=\"-1\" data-aria-posinset=\"1\" data-aria-level=\"1\"><span data-contrast=\"auto\">Compiler try to find out where is main method\u00a0<\/span><span data-ccp-props=\"{&quot;134233279&quot;:true,&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"4\" aria-setsize=\"-1\" data-aria-posinset=\"2\" data-aria-level=\"1\"><span data-contrast=\"auto\">Reference for same class.<\/span><span data-ccp-props=\"{&quot;134233279&quot;:true,&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/li>\n<\/ul>\n<h4><b><span data-contrast=\"auto\">Question: What is the difference between primary constructor and function?<\/span><\/b><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/h4>\n<p><b><span data-contrast=\"auto\">Answer:\u00a0<\/span><\/b><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">Primary constructor allows to perform encapsulation.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">Encapsulation has two points: It allows to perform getter and setter method.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p><b><span data-contrast=\"auto\">Getter:<\/span><\/b><span data-contrast=\"auto\"> Try to access the value. It allows only access. Does not allow to change it. By default, immutable. Immutable means val.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p><b><span data-contrast=\"auto\">Setter:<\/span><\/b><span data-contrast=\"auto\"> Setter can change and can change means mutable.<\/span><\/p>\n<p>&nbsp;<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">class Scala_Wel{ \r\n  def area(len:Double,wid:Double):Double ={ \r\n    val c = (len*wid) \r\n    println(c) \r\n  } \r\n} \r\nobject Scal{ \r\n  def main(args: Array[String]):Double = { \r\n    val s1 = new Scala_Wel() \r\n    val s2 = new Scala_Wel() \r\n    val s3 = new Scala_Wel() \r\n    val s4 = new Scala_Wel() \r\n    val s5 = new Scala_Wel() \r\n    s1.area(40.96, 20.00) \r\n    s2.area(35.84, 22.00) \r\n    s3.area(30.00, 16.00) \r\n    s4.area(45.5, 25.00) \r\n    s5.area(41.3, 23.35) \r\n  } \r\n \r\n}<\/pre>\n<p>&nbsp;<\/p>\n<p><span data-contrast=\"auto\">Classes, Functions and variables all these are by default public.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">when we don\u2019t write in Scala by default<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p><b><span data-contrast=\"auto\">No modifiers:<\/span><\/b><span data-contrast=\"auto\"> by default, public<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p><b><span data-contrast=\"auto\">modifiers:<\/span><\/b><span data-contrast=\"auto\">\u00a0<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">only the same class can access or the subclass can access or the same package can access.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">Types of modifiers:\u00a0<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<ol>\n<li data-leveltext=\"%1.\" data-font=\"Arial\" data-listid=\"1\" aria-setsize=\"-1\" data-aria-posinset=\"1\" data-aria-level=\"1\"><span data-contrast=\"auto\">No modifier<\/span><span data-ccp-props=\"{&quot;134233279&quot;:true,&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/li>\n<\/ol>\n<ol>\n<li data-leveltext=\"%1.\" data-font=\"Arial\" data-listid=\"1\" aria-setsize=\"-1\" data-aria-posinset=\"2\" data-aria-level=\"1\"><span data-contrast=\"auto\">Private\u00a0<\/span><span data-ccp-props=\"{&quot;134233279&quot;:true,&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/li>\n<\/ol>\n<ol>\n<li data-leveltext=\"%1.\" data-font=\"Arial\" data-listid=\"1\" aria-setsize=\"-1\" data-aria-posinset=\"3\" data-aria-level=\"1\"><span data-contrast=\"auto\">Protected<\/span><span data-ccp-props=\"{&quot;134233279&quot;:true,&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/li>\n<\/ol>\n<p><b><span data-contrast=\"auto\">What is the access pattern?<\/span><\/b><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"5\" aria-setsize=\"-1\" data-aria-posinset=\"1\" data-aria-level=\"1\"><span data-contrast=\"auto\">Outside package\u00a0<\/span><span data-ccp-props=\"{&quot;134233279&quot;:true,&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"5\" aria-setsize=\"-1\" data-aria-posinset=\"2\" data-aria-level=\"1\"><span data-contrast=\"auto\">Same package<\/span><span data-ccp-props=\"{&quot;134233279&quot;:true,&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/li>\n<\/ul>\n<table data-tablestyle=\"MsoTableGrid\" data-tablelook=\"1184\" aria-rowcount=\"5\">\n<tbody>\n<tr aria-rowindex=\"1\">\n<td colspan=\"7\" data-celllook=\"0\"><b><span data-contrast=\"auto\">Modifiers<\/span><\/b><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:2,&quot;335551620&quot;:2,&quot;335559740&quot;:256}\">\u00a0<\/span><\/td>\n<\/tr>\n<tr aria-rowindex=\"2\">\n<td data-celllook=\"0\"><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:256}\">\u00a0<\/span><\/td>\n<td data-celllook=\"0\"><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:256}\">\u00a0<\/span><\/td>\n<td data-celllook=\"0\"><b><span data-contrast=\"auto\">Outside<\/span><\/b><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p><b><span data-contrast=\"auto\">Package<\/span><\/b><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:256}\">\u00a0<\/span><\/td>\n<td data-celllook=\"0\"><b><span data-contrast=\"auto\">Same Package<\/span><\/b><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:256}\">\u00a0<\/span><\/td>\n<td data-celllook=\"0\"><b><span data-contrast=\"auto\">Same Class<\/span><\/b><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:256}\">\u00a0<\/span><\/td>\n<td data-celllook=\"0\"><b><span data-contrast=\"auto\">Sub Class<\/span><\/b><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:256}\">\u00a0<\/span><\/td>\n<td data-celllook=\"0\"><b><span data-contrast=\"auto\">Companion Class<\/span><\/b><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:256}\">\u00a0<\/span><\/td>\n<\/tr>\n<tr aria-rowindex=\"3\">\n<td data-celllook=\"0\"><b><span data-contrast=\"auto\">1<\/span><\/b><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:256}\">\u00a0<\/span><\/td>\n<td data-celllook=\"0\"><span data-contrast=\"auto\">No Modifier<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:256}\">\u00a0<\/span><\/td>\n<td data-celllook=\"0\"><span data-contrast=\"auto\">Yes<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:256}\">\u00a0<\/span><\/td>\n<td data-celllook=\"0\"><span data-contrast=\"auto\">Yes<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335559740&quot;:256}\">\u00a0<\/span><\/td>\n<td data-celllook=\"0\"><span data-contrast=\"auto\">Yes\u00a0<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:256}\">\u00a0<\/span><\/td>\n<td data-celllook=\"0\"><span data-contrast=\"auto\">Yes<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:256}\">\u00a0<\/span><\/td>\n<td data-celllook=\"0\"><span data-contrast=\"auto\">Yes<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:256}\">\u00a0<\/span><\/td>\n<\/tr>\n<tr aria-rowindex=\"4\">\n<td data-celllook=\"0\"><b><span data-contrast=\"auto\">2<\/span><\/b><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:256}\">\u00a0<\/span><\/td>\n<td data-celllook=\"0\"><span data-contrast=\"auto\">Private<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:256}\">\u00a0<\/span><\/td>\n<td data-celllook=\"0\"><span data-contrast=\"auto\">No<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:256}\">\u00a0<\/span><\/td>\n<td data-celllook=\"0\"><span data-contrast=\"auto\">No<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:256}\">\u00a0<\/span><\/td>\n<td data-celllook=\"0\"><span data-contrast=\"auto\">Yes<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:256}\">\u00a0<\/span><\/td>\n<td data-celllook=\"0\"><span data-contrast=\"auto\">No<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:256}\">\u00a0<\/span><\/td>\n<td data-celllook=\"0\"><span data-contrast=\"auto\">Yes<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:256}\">\u00a0<\/span><\/td>\n<\/tr>\n<tr aria-rowindex=\"5\">\n<td data-celllook=\"0\"><b><span data-contrast=\"auto\">3<\/span><\/b><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:256}\">\u00a0<\/span><\/td>\n<td data-celllook=\"0\"><span data-contrast=\"auto\">Protected<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:256}\">\u00a0<\/span><\/td>\n<td data-celllook=\"0\"><span data-contrast=\"auto\">No<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:256}\">\u00a0<\/span><\/td>\n<td data-celllook=\"0\"><span data-contrast=\"auto\">No<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:256}\">\u00a0<\/span><\/td>\n<td data-celllook=\"0\"><span data-contrast=\"auto\">Yes<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:256}\">\u00a0<\/span><\/td>\n<td data-celllook=\"0\"><span data-contrast=\"auto\">Yes<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:256}\">\u00a0<\/span><\/td>\n<td data-celllook=\"0\"><span data-contrast=\"auto\">Yes<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559740&quot;:256}\">\u00a0<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"6\" aria-setsize=\"-1\" data-aria-posinset=\"1\" data-aria-level=\"1\"><b><span data-contrast=\"auto\">Singleton object:<\/span><\/b><span data-contrast=\"auto\"> means there are no class only object. whenever we need to work with a static kind of concept. we want to implement once we don\u2019t want to instantiate. It is used for static cases.<\/span><span data-ccp-props=\"{&quot;134233279&quot;:true,&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"6\" aria-setsize=\"-1\" data-aria-posinset=\"2\" data-aria-level=\"1\"><b><span data-contrast=\"auto\">Companion class:<\/span><\/b><span data-contrast=\"auto\"> class and object both have same name\u00a0<\/span><span data-ccp-props=\"{&quot;134233279&quot;:true,&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/li>\n<\/ul>\n<p><span data-contrast=\"auto\">got to Scala class: kind it has class, case object, object, case object, trait.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">always we need a main method. Without main method compiler will never wake up.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<h4><b><span data-contrast=\"auto\">Extension of main method:<\/span><\/b><b><span data-contrast=\"auto\"> extends App<\/span><\/b><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/h4>\n<p><span data-contrast=\"auto\">If we use extends App, then no need to type main method<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p>&nbsp;<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">object Prop_Vol extends App { \r\n  \/\/def main(args:Array[String]) ={} \r\n  println(\"Helli Scala\") \r\n \r\n}<\/pre>\n<p><span data-contrast=\"auto\">Helli Scala<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">Process finished with exit code 0<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p><b><span data-contrast=\"auto\">How to create a method:?<\/span><\/b><span data-contrast=\"auto\">\u00a0<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">def main(args:Array[String]): Unit\u00a0 = {<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">}<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">main method cannot have more methods inside. We cannot write methods inside method\u00a0<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p><b><span data-contrast=\"auto\">For example:\u00a0<\/span><\/b><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">def main(args:Array[String]): Unit = {<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">def vol &#8230;&#8230;&#8230;.cannot write like this inside def function def vol\u00a0<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">}<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">def cannot have inside def.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p><b><span data-contrast=\"auto\">Example of singleton object.<\/span><\/b><span data-contrast=\"auto\">\u00a0<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">The below example is for singleton. It\u2019s a singleton object because there no class directly object<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p>&nbsp;<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">object Prop_Vol  { \r\n   def main(args:Array[String])={ \r\n     def vol(l:Double,w:Double,h:Double)={ \r\n       (l*w*h) \r\n     } \r\n     println(\"This is vol of marriage hall\"+vol(17.8,12.5,19.0)) \r\n  } \r\n \r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">This is vol of marriage hall4227.5<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">Process finished with exit code 0<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p><b><span data-contrast=\"auto\">How to instantiate Prop_Vol?<\/span><\/b><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p>&nbsp;<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">object Prop_Vol  { \r\n   def main(args:Array[String])= { \r\n     println(\"This is vol of marriage hall\"+vol(17.8,12.5,19.0)) \r\n   } \r\n  def vol(l:Double,w:Double,h:Double)= { \r\n    (l * w * h) \r\n   val p = new Prop_Vol() \r\n  } \r\n \r\n \r\n}<\/pre>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">object Prop_Vol  { \r\n   def main(args:Array[String])= { \r\n     println(\"This is vol of marriage hall\"+vol(17.8,12.5,19.0)) \r\n     val p = new Prop_Vol() \r\n  def vol(l:Double,w:Double,h:Double)= { \r\n    (l * w * h) \r\n   \r\n  } \r\n \r\n \r\n} \r\n\r\nPage Break\r\n \r\n\r\nCan not resolve symbol Pro_Vol \r\n\r\nobject Prop_Vol  { \r\n   def main(args:Array[String])= { \r\n     println(\"This is for area1:\"  +area(len =18.0f,wid= 16.5f)) \r\n     println(\"This is for area 2:\" +area(len=20.0f,wid=18.2f)) \r\n   } \r\n  def area(len:Float,wid:Float) = { \r\n    (len*wid) \r\n  } \r\n}<\/pre>\n<p><span data-contrast=\"auto\">This is for area1:297.0<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">This is for area 2:364.0<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">Process finished with exit code 0<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">We cannot instantiate here we can just write a method a same object. But outside object it will get an issue.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">what are Scala class object case object, trait and Scala worksheet in intellij IDE and how to select for efficient programming\u00a0<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<h4><b><span data-contrast=\"auto\">Factorial function:<\/span><\/b><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/h4>\n<p><span data-contrast=\"auto\">Factorial function is recursion. recursive means function calling function.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">5! = 5*4*3*2*1<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p><b><span data-contrast=\"auto\">logic\u00a0<\/span><\/b><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">n! =n*(n-1) *(n-2) *(n-3) &#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.(n-n+1)<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p><b><span data-contrast=\"auto\">How to use logic in syntax?<\/span><\/b><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">Python logic for factorial, java logic for factorial, Scala logic for factorial. logic is same in all the languages only syntax is different\u00a0<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">\u00a0Fibonacci series :0,1, (0+1=1), (1+1=2), (1+2=3), (2+3=5), &#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p><b><span data-contrast=\"auto\">any recursive function needs return type.<\/span><\/b><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p><b><span data-contrast=\"auto\">How write factorial methods in Scala\u00a0<\/span><\/b><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p><b><span data-contrast=\"auto\">Factorial without using class<\/span><\/b><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">object Prop_Vol  { \r\n   def main(args:Array[String])= { \r\n     println(\"output of factorial 5!:\" +  facto(5)) \r\n   } \r\n   def facto(n:BigInt):BigInt = { \r\n     if(n==0)1 else n*facto(n-1) \r\n   } \r\n} \r\n\r\noutput of factorial 5!:120 \r\n\r\nProcess finished with exit code 0 \r\n\r\nobject Prop_Vol  { \r\n   def main(args:Array[String])= { \r\n     println(\"output of factorial 10!:\" +  facto(10)) \r\n   } \r\n   def facto(n:BigInt):BigInt = { \r\n     if(n==0)1 else n*facto(n-1) \r\n   } \r\n} \r\n\r\noutput of factorial 10!:3628800 \r\n\r\nProcess finished with exit code 0 \r\n\r\nobject Prop_Vol  { \r\n   def main(args:Array[String])= { \r\n     println(\"output of factorial 6!:\" +  facto(6)) \r\n   } \r\n   def facto(n:BigInt):BigInt = { \r\n     if(n==0)1 else n*facto(n-1) \r\n   } \r\n} \r\n\r\n \r\n\r\noutput of factorial 6!:720 \r\n\r\nProcess finished with exit code 0 \r\n\r\nobject Prop_Vol  { \r\n   def main(args:Array[String])= { \r\n     println(\"output of factorial 3!:\" +  facto(3)) \r\n   } \r\n   def facto(n:BigInt):BigInt = { \r\n     if(n==0)1 else n*facto(n-1) \r\n   } \r\n} \r\n\r\noutput of factorial 3!:6 \r\n\r\nProcess finished with exit code 0<\/pre>\n<h3><b><span data-contrast=\"auto\">Factorial using class<\/span><\/b><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/h3>\n<p><span data-contrast=\"auto\">the factorial using class: in class we can write function within function then we can call it from my object .<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p>&nbsp;<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">class Factorial_new { \r\n  def facto(n:BigInt):BigInt={ \r\n    if(n==0)1 else n*(n-1) \r\n  } \r\n} \r\n  object Prop_Vol1{ \r\n    def main(args:Array[String])={ \r\n      \/\/ create instantiation for class \r\n       val fn = new Factorial_new() \r\n       println(fn.facto(5)) \r\n    } \r\n \r\n  } \r\n\r\n20<\/pre>\n<p>&nbsp;<\/p>\n<p><span class=\"TextRun Underlined SCXW58871877 BCX0\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW58871877 BCX0\">Concept of Private:<\/span><span class=\"NormalTextRun SCXW58871877 BCX0\">\u00a0<\/span><\/span><span class=\"EOP SCXW58871877 BCX0\" data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p><span class=\"TextRun SCXW268061584 BCX0\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW268061584 BCX0\">private can be accessible only an only within the class no outside<\/span><\/span><span class=\"EOP SCXW268061584 BCX0\" data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">private can be accessible only an only within the class no outside class Factorial_new { \r\n  private val n = 5 \r\n  def facto(n:BigInt):BigInt = { \r\n    if(n==0)1 else n*facto(n-1) \r\n  } \r\n} \r\n  object Prop { \r\n    def main(args:Array[String])={ \r\n       val f = new Factorial_new() \r\n       f.n \r\n    } \r\n \r\n  } \r\n\r\n \r\n\r\nf.n: here symbol is inaccessible from this place . due to private it  can not be accessible outside the class. \r\n\r\nclass Factorial_new { \r\n  private val n = 0; \r\n  def facto(n:BigInt):BigInt = { \r\n    if(n==0)1 else n*facto(n-1) \r\n  } \r\n} \r\n  object Prop { \r\n    def main(args:Array[String])={ \r\n       val f = new Factorial_new() \r\n       println(f.facto(6)) \r\n    } \r\n \r\n  } \r\n\r\n720<\/pre>\n<p><b><span data-contrast=\"auto\">Concept of companion:<\/span><\/b><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">Companion when class and object share the same names.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">class Factorial_new { \r\n  private val n = 0; \r\n  def facto(n:BigInt):BigInt = { \r\n    if(n==0)1 else n*facto(n-1) \r\n  } \r\n} \r\n  object Factorial_new { \r\n    def main(args: Array[String]) = { \r\n      val f = new Factorial_new() \r\n      println(f.n) \r\n    } \r\n  } \r\n\r\n0<\/pre>\n<p><b><span data-contrast=\"auto\">Conditional expressions:<\/span><\/b><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"2\" aria-setsize=\"-1\" data-aria-posinset=\"1\" data-aria-level=\"1\"><span data-contrast=\"auto\">if\u00a0<\/span><span data-ccp-props=\"{&quot;134233279&quot;:true,&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"2\" aria-setsize=\"-1\" data-aria-posinset=\"2\" data-aria-level=\"1\"><span data-contrast=\"auto\">if else\u00a0<\/span><span data-ccp-props=\"{&quot;134233279&quot;:true,&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/li>\n<\/ul>\n<p><span data-contrast=\"auto\">Whenever we want to use conditional <a href=\"https:\/\/prwatech.in\/blog\/\">expressions<\/a>. Make sure <a href=\"https:\/\/www.tableau.com\/\">that<\/a> you are writing within the classes.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">and if you are creating a function you can write within the within the singleton object.<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">if-else loop then you need to have a class.\u00a0<\/span><span data-ccp-props=\"{&quot;201341983&quot;:0,&quot;335551550&quot;:6,&quot;335551620&quot;:6,&quot;335559739&quot;:160,&quot;335559740&quot;:256}\">\u00a0<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>SCALA- PRACTICALS PART 3 &nbsp; Question: Calculate area of hall for 5 flats in a floor.\u00a0 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Solution:\u00a0 Suppose we have A building with 9th floor. And we have to calculate the area of 5 flat whose dimension are given below\u00a0\u00a0 A-901 length len= 40.96, Width wid =20.00\u00a0 A-902 length len =35.84, Width wid =22.08\u00a0 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[565,1698],"tags":[560,1963,576,1962,1965,1964],"class_list":["post-9688","post","type-post","status-publish","format-standard","hentry","category-scala","category-scala-modules-scala","tag-a-scala-tutorial","tag-part-iii-by-dean-wampler","tag-scala","tag-scala-3-contextual-abstractions","tag-scala-features-scala-3-book","tag-scala-tutorial-part-3-im-gonna-cover-some-more-list-and"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>SCALA- PRACTICALS PART 3 - Prwatech<\/title>\n<meta name=\"description\" content=\"Master Scala Practicals Part 3 - Dive deep with our expert instructors and comprehensive curriculum, Enroll now.\" \/>\n<meta name=\"robots\" content=\"noindex, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SCALA- PRACTICALS PART 3 - Prwatech\" \/>\n<meta property=\"og:description\" content=\"Master Scala Practicals Part 3 - Dive deep with our expert instructors and comprehensive curriculum, Enroll now.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-practicals-part-3\/\" \/>\n<meta property=\"og:site_name\" content=\"Prwatech\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/prwatech.in\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-01-17T07:29:16+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-04-11T07:27:53+00:00\" \/>\n<meta name=\"author\" content=\"Prwatech\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@Eduprwatech\" \/>\n<meta name=\"twitter:site\" content=\"@Eduprwatech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Prwatech\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-practicals-part-3\/\",\"url\":\"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-practicals-part-3\/\",\"name\":\"SCALA- PRACTICALS PART 3 - Prwatech\",\"isPartOf\":{\"@id\":\"https:\/\/prwatech.in\/blog\/#website\"},\"datePublished\":\"2022-01-17T07:29:16+00:00\",\"dateModified\":\"2024-04-11T07:27:53+00:00\",\"author\":{\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3\"},\"description\":\"Master Scala Practicals Part 3 - Dive deep with our expert instructors and comprehensive curriculum, Enroll now.\",\"breadcrumb\":{\"@id\":\"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-practicals-part-3\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-practicals-part-3\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-practicals-part-3\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/prwatech.in\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SCALA- PRACTICALS PART 3\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/prwatech.in\/blog\/#website\",\"url\":\"https:\/\/prwatech.in\/blog\/\",\"name\":\"Prwatech\",\"description\":\"Share Ideas, Start Something Good.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/prwatech.in\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3\",\"name\":\"Prwatech\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g\",\"caption\":\"Prwatech\"},\"url\":\"https:\/\/prwatech.in\/blog\/author\/prwatech123\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"SCALA- PRACTICALS PART 3 - Prwatech","description":"Master Scala Practicals Part 3 - Dive deep with our expert instructors and comprehensive curriculum, Enroll now.","robots":{"index":"noindex","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"og_locale":"en_US","og_type":"article","og_title":"SCALA- PRACTICALS PART 3 - Prwatech","og_description":"Master Scala Practicals Part 3 - Dive deep with our expert instructors and comprehensive curriculum, Enroll now.","og_url":"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-practicals-part-3\/","og_site_name":"Prwatech","article_publisher":"https:\/\/www.facebook.com\/prwatech.in\/","article_published_time":"2022-01-17T07:29:16+00:00","article_modified_time":"2024-04-11T07:27:53+00:00","author":"Prwatech","twitter_card":"summary_large_image","twitter_creator":"@Eduprwatech","twitter_site":"@Eduprwatech","twitter_misc":{"Written by":"Prwatech","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-practicals-part-3\/","url":"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-practicals-part-3\/","name":"SCALA- PRACTICALS PART 3 - Prwatech","isPartOf":{"@id":"https:\/\/prwatech.in\/blog\/#website"},"datePublished":"2022-01-17T07:29:16+00:00","dateModified":"2024-04-11T07:27:53+00:00","author":{"@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3"},"description":"Master Scala Practicals Part 3 - Dive deep with our expert instructors and comprehensive curriculum, Enroll now.","breadcrumb":{"@id":"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-practicals-part-3\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-practicals-part-3\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-practicals-part-3\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/prwatech.in\/blog\/"},{"@type":"ListItem","position":2,"name":"SCALA- PRACTICALS PART 3"}]},{"@type":"WebSite","@id":"https:\/\/prwatech.in\/blog\/#website","url":"https:\/\/prwatech.in\/blog\/","name":"Prwatech","description":"Share Ideas, Start Something Good.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/prwatech.in\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3","name":"Prwatech","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g","caption":"Prwatech"},"url":"https:\/\/prwatech.in\/blog\/author\/prwatech123\/"}]}},"_links":{"self":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/9688","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/comments?post=9688"}],"version-history":[{"count":6,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/9688\/revisions"}],"predecessor-version":[{"id":11345,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/9688\/revisions\/11345"}],"wp:attachment":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/media?parent=9688"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/categories?post=9688"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/tags?post=9688"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}