{"id":307,"date":"2020-10-14T15:54:53","date_gmt":"2020-10-14T10:24:53","guid":{"rendered":"http:\/\/sumitjangid.com\/?p=307"},"modified":"2020-10-14T15:54:53","modified_gmt":"2020-10-14T10:24:53","slug":"abstract-class-and-method","status":"publish","type":"post","link":"http:\/\/sumitjangid.com\/index.php\/2020\/10\/14\/abstract-class-and-method\/","title":{"rendered":"Abstract Class and Method"},"content":{"rendered":"\n<p>Data&nbsp;<strong>abstraction<\/strong>&nbsp;is the process of hiding certain details and showing only essential information to the user.<br>Abstraction can be achieved with either&nbsp;<strong>abstract classes<\/strong>&nbsp;or&nbsp;<a href=\"https:\/\/www.w3schools.com\/cs\/cs_interface.asp\"><strong>interfaces<\/strong><\/a>&nbsp;(which you will learn more about in the next chapter).<\/p>\n\n\n\n<p>The&nbsp;<code>abstract<\/code>&nbsp;keyword is used for classes and methods:<\/p>\n\n\n\n<ul><li><strong>Abstract class:<\/strong>&nbsp;is a restricted class that cannot be used to create objects (to access it, it must be inherited from another class).<\/li><li><strong>Abstract method:<\/strong>&nbsp;can only be used in an abstract class, and it does not have a body. The body is provided by the derived class (inherited from).<\/li><\/ul>\n\n\n\n<p>An abstract class can have both abstract and regular methods:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>abstract class mcn {  \r\n        public int add(int a, int b) {  \r\n            return (a + b);  \r\n        }  \r\n    }  \r\n    class mcn1: mcn {  \r\n        public int mul(int a, int b) {  \r\n            return a * b;  \r\n        }  \r\n    }  \r\n    class test {  \r\n        static void Main(string&#91;] args) {  \r\n            mcn1 ob = new mcn1();  \r\n            int result = ob.add(5, 10);  \r\n            Console.WriteLine(\"the result is {0}\", result);  \r\n        }  \r\n    } <\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Data&nbsp;abstraction&nbsp;is the process of hiding certain details and showing only essential information to the user.Abstraction can be achieved with either&nbsp;abstract classes&nbsp;or&nbsp;interfaces&nbsp;(which you will learn more about in the next chapter). The&nbsp;abstract&nbsp;keyword is used for classes&hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[3,4,2],"tags":[],"_links":{"self":[{"href":"http:\/\/sumitjangid.com\/index.php\/wp-json\/wp\/v2\/posts\/307"}],"collection":[{"href":"http:\/\/sumitjangid.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/sumitjangid.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/sumitjangid.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/sumitjangid.com\/index.php\/wp-json\/wp\/v2\/comments?post=307"}],"version-history":[{"count":1,"href":"http:\/\/sumitjangid.com\/index.php\/wp-json\/wp\/v2\/posts\/307\/revisions"}],"predecessor-version":[{"id":308,"href":"http:\/\/sumitjangid.com\/index.php\/wp-json\/wp\/v2\/posts\/307\/revisions\/308"}],"wp:attachment":[{"href":"http:\/\/sumitjangid.com\/index.php\/wp-json\/wp\/v2\/media?parent=307"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/sumitjangid.com\/index.php\/wp-json\/wp\/v2\/categories?post=307"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/sumitjangid.com\/index.php\/wp-json\/wp\/v2\/tags?post=307"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}