{"id":155214,"date":"2023-04-01T08:27:56","date_gmt":"2023-04-01T08:27:56","guid":{"rendered":"https:\/\/www.henryharvin.com\/blog\/?p=155214"},"modified":"2023-04-06T07:08:36","modified_gmt":"2023-04-06T07:08:36","slug":"oops-concepts-in-java-with-examples","status":"publish","type":"post","link":"https:\/\/www.henryharvin.com\/blog\/oops-concepts-in-java-with-examples\/","title":{"rendered":"OOPs concepts in Java With Examples"},"content":{"rendered":"\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">&nbsp;In this blog, we will go over the fundamentals of OOPs concepts in Java. OOPs is a language given to program the user to build software that rests on classes and objects. we modularize the real world, by implementing and inheriting things together. an object is a combination of data that has data members and functions. oops uses different concepts such as abstraction, polymorphism, inheritance, and encapsulation. maintenance, reusability, and adaptability are the advantages of oops in java.<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">What is Oops?<\/h3>\n\n\n\n<p>OOPs is a computer language used to design and build software with objects and classes. Data and attributes are the concepts of objects. The basic unit of programming is an object. each object has certain attributes and exhibits different behavior.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img fetchpriority=\"high\" decoding=\"async\" src=\"https:\/\/hh-certificates.sgp1.digitaloceanspaces.com\/blog\/wp-content\/uploads\/2023\/03\/20085745\/oops-concept-724x1024.jpg\" alt=\"\" class=\"wp-image-155225\" width=\"227\" height=\"321\" srcset=\"https:\/\/hh-certificates.sgp1.digitaloceanspaces.com\/blog\/wp-content\/uploads\/2023\/03\/20085745\/oops-concept-724x1024.jpg 724w, https:\/\/hh-certificates.sgp1.digitaloceanspaces.com\/blog\/wp-content\/uploads\/2023\/03\/20085745\/oops-concept-212x300.jpg 212w, https:\/\/hh-certificates.sgp1.digitaloceanspaces.com\/blog\/wp-content\/uploads\/2023\/03\/20085745\/oops-concept-768x1086.jpg 768w, https:\/\/hh-certificates.sgp1.digitaloceanspaces.com\/blog\/wp-content\/uploads\/2023\/03\/20085745\/oops-concept-1086x1536.jpg 1086w, https:\/\/hh-certificates.sgp1.digitaloceanspaces.com\/blog\/wp-content\/uploads\/2023\/03\/20085745\/oops-concept-1448x2048.jpg 1448w, https:\/\/hh-certificates.sgp1.digitaloceanspaces.com\/blog\/wp-content\/uploads\/2023\/03\/20085745\/oops-concept.jpg 1587w\" sizes=\"(max-width: 227px) 100vw, 227px\" \/><figcaption>OOPS<\/figcaption><\/figure><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">What is OOPs in java?<\/h3>\n\n\n\n<p>Java is a secured programming language developed by sun microsystem. James Gosling is the founder of Java. OOPs is a primary source code to implement the data in the system. it also manipulates data that represents to focus on the object data.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">What is OOPs concept in java?<\/h3>\n\n\n\n<p>Programming&#8217;s essential tenets based on object-oriented programming (OOP) ideas. The goal of OOPs in Java is to increase code readability and reuse by defining Java programs.<\/p>\n\n\n\n<p>Java datatype and variable<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">What is a data type?<\/h3>\n\n\n\n<p>    A data type is a variable that stores in the form of size and values.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;<strong>Declaring a variable<\/strong><\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;int u,v,w;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Char z;<\/p>\n\n\n\n<p>&nbsp;&nbsp;<strong> Initialize a variable<\/strong><\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;          x=\u201dz\u201d;<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;           &nbsp;y=2<\/p>\n\n\n\n<p>&nbsp;&nbsp;Now it is int a=5,b=8<\/p>\n\n\n\n<p><strong>Variable types of oops in java<\/strong><\/p>\n\n\n\n<p>&nbsp;1. local<\/p>\n\n\n\n<p> 2. instance<\/p>\n\n\n\n<p> 3. static<\/p>\n\n\n\n<p><strong>    Example<\/strong><\/p>\n\n\n\n<p>&nbsp;         Class main<\/p>\n\n\n\n<p>          Static int&nbsp; x=10;<\/p>\n\n\n\n<p>           Int data=50;<\/p>\n\n\n\n<p>           Void method()<\/p>\n\n\n\n<p>             Int y= 20;<\/p>\n\n\n\n<p>             }<\/p>\n\n\n\n<p>             }<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">OOPs concept in java<\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li>Objects<\/li><li>Classes<\/li><li>Abstraction<\/li><li>Inheritance<\/li><li>Encapsulation<\/li><li>Polymorphism<\/li><\/ul>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large is-resized\"><img decoding=\"async\" src=\"https:\/\/hh-certificates.sgp1.digitaloceanspaces.com\/blog\/wp-content\/uploads\/2023\/03\/20091917\/Screenshot-2023-03-20-144810.png\" alt=\"\" class=\"wp-image-155226\" width=\"462\" height=\"350\" \/><figcaption>oops concepts<\/figcaption><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Object<\/strong><\/h2>\n\n\n\n<p>Programming&#8217;s fundamental building block is an object. Object recognizes their distinctive names. an object defined as a collection of data members and operations also called methods.<\/p>\n\n\n\n<p>For example, a car is an object which has attributes like color, model, and year of manufacturing. and its functions start, stop, and move.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Classes<\/h2>\n\n\n\n<p>&nbsp;A class can form by grouping objects with similar properties.<\/p>\n\n\n\n<p>&nbsp;<strong>Example<\/strong>: we have a Class of Cars in which Santro Xing, Alto, and WaganR represent individual Objects. <\/p>\n\n\n\n<p>In this context, each Car Object will have its Model, Year of Manufacture, Color, Top Speed, Engine Power, and so on, which form Car Class Properties, and the associated actions, i.e., object functions like Start, Move and Stop, which form Car Class Methods.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Abstraction and encapsulation<\/h2>\n\n\n\n<p>&nbsp;Grouping of data and methods into a single entity&nbsp;known as data encapsulation or data hiding.<\/p>\n\n\n\n<p>&nbsp;Encapsulation is a data hiding&nbsp;used to protect data from the outside world.&nbsp;&nbsp;<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Inheritance<\/h2>\n\n\n\n<p>It is extending an existing class to create a new one. Inheritance is the process by creating a new class by which objects of one class inherit the properties of objects of a different class.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">polymorphism<\/h2>\n\n\n\n<p>&nbsp;A polymorphic operation displays various behavior depending on the situation. The type of data used in the process, which determines the behaviour.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Benefits of OOPs in java<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>The data-hiding principle assists programmers in creating secure programs.<\/li><li>We can drop code repetition and extend the use of existing classes by using inheritance.<\/li><li>It is simple to divide work in a project into objects.<\/li><li>Object-oriented systems scale well from small to large systems.<\/li><li>Software complicity is easily manageable.<\/li><\/ul>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Concepts of OOPs comparison with different programming languages using an example <\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">An illustration of how java&#8217;s oops principles differ from other programming paradigms<\/h4>\n\n\n\n<p>Suppose you want to create a new account with functions like Account number, account balance.<\/p>\n\n\n\n<p>         First, we will apply this in an unstructured programming language. Unstructured programming languages were the first of all programming languages.<\/p>\n\n\n\n<p class=\"has-text-align-center\">Int account_num=5;<\/p>\n\n\n\n<p class=\"has-text-align-center\">Int account_bal=1000;<\/p>\n\n\n\n<p>Again a deposit made<\/p>\n\n\n\n<p class=\"has-text-align-center\">Account_bal=account_bal+1000<\/p>\n\n\n\n<p>Display the account balance<\/p>\n\n\n\n<p class=\"has-text-align-center\">printf(\u201caccount_num=%d,account bal\u201d)<\/p>\n\n\n\n<p class=\"has-text-align-center\">printf(\u201caccount_bal=%d,account bal\u201d)<\/p>\n\n\n\n<p>Now withdraw 500<\/p>\n\n\n\n<p class=\"has-text-align-center\">account_bal=account_bal-500<\/p>\n\n\n\n<p>Now again you need to display the account balance<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>In this unstructured program, codes will get repeated again and again<\/strong><\/p>\n\n\n\n<p>We will apply the same code to Structured programming<\/p>\n\n\n\n<p class=\"has-text-align-center\">printf(\u201caccount_num=%d,account bal\u201d)<\/p>\n\n\n\n<p class=\"has-text-align-center\">printf(\u201caccount_bal=%d,account bal\u201d)<\/p>\n\n\n\n<p class=\"has-text-align-center\">Void showdata()<\/p>\n\n\n\n<p>Here we use void call data to call the function itself. whenever needed it calls a function&nbsp;<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>The same code we will apply in oops concepts(object-oriented programming)<\/strong><\/p>\n\n\n\n<p>Class account<\/p>\n\n\n\n<p>{<\/p>\n\n\n\n<p>Int account_num;<\/p>\n\n\n\n<p>Int account_bal;<\/p>\n\n\n\n<p>Public void showdata()<\/p>\n\n\n\n<p>{<\/p>\n\n\n\n<p>system.out.println(\u201caccount num\u201d+account_num)<\/p>\n\n\n\n<p>system.out.println(\u201caccount bal\u201d+account_bal)<\/p>\n\n\n\n<p>}<\/p>\n\n\n\n<p>}<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>A software program is an fundamental aspect which has the ability to conduct specific operations on data and have data available. The idea of merging data and operations came from software programming experts. Object Oriented Programming, or concepts of OOPs in java, was thus born.<\/p>\n\n\n\n<p class=\"has-text-align-center\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Int account_num=5;\u2192DATA<\/p>\n\n\n\n<p class=\"has-text-align-center\">&nbsp;Int account_bal=1000;<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p class=\"has-text-align-center\">Void showdata()\u2192ACTIONS<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">OOPS concepts in java with example<\/h2>\n\n\n\n<p><strong>Objects &amp; classes<\/strong><\/p>\n\n\n\n<p>&nbsp;OOPs is a&nbsp; concept of java in a class, all of an object&#8217;s functions and data converted to user-defined data types. A class is a &#8220;data type,&#8221; and an object is a &#8220;variable&#8221; of that type. After a class created, the maximum amount of its components get constructed.<\/p>\n\n\n\n<p>&nbsp;<strong>Syntax<\/strong><\/p>\n\n\n\n<p>Access modifier class&lt;class name&gt;<br>{<br>Data member;<br>Method;<br>}<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class School\n{\nString x=\"henry harvin\";public static void main(String&#091;] args) \n{\nschool myobj=new school();\nSystem.out.println(myobj.x);\n}\n}<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>Create the class school. To create an object, specify the class name, followed by the object name, and use the keyword new.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>school Myobj= new school ()<\/p>\n\n\n\n<p>Created a java file called myschool.java and prints henry harvin on the screen.&nbsp;<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>You can also create many objects in the same class<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Public class myschool\n{\nstring x=henry harvin;\nstring y=yyy;\n}\nClass courses\n{\nPublic static void main (string &#091; ] args)\n{\nMyschool myobj1=new myobj1();\nMyschool myobj2=new myobj2();\nsystem.out.println(myobj1.x);\nsystem.out.println(myobj2.y);\n}\n}\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Points to remember<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>Java requires that every line of code run within a class. We gave the class in our example the name Myschool. Every class should begin with an uppercase letter.<\/li><li>Java is case-sensitive: &#8220;My school&#8221; and &#8220;school&#8221; has a different meaning.<\/li><li>The main() method will run any code inside of it. The keywords before and after the main are unimportant.&nbsp;<\/li><li>We can print a line of text on the screen within the main() method using the println() method.<\/li><li>The curly braces indicate the beginning and end of a code block.<\/li><li>Here system in out represents output a component of the built-in Java class. A value printed on the screen using the println() method, short for &#8220;print line&#8221; (or a file).<\/li><li>Each statement must end with a semicolon.<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Inheritance<\/h2>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;The \u201csuperclass\u201d is the existing class and the \u201csubclass\u201d is the new class. superclass derived from the child class and subclass derived from the parent class.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Types of inheritance&nbsp;<\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li>&nbsp;Single inheritance<\/li><li>Multi level inheritance<\/li><li>Hybrid<\/li><li>Hierarchical inheritance<\/li><li>Multilevel inheritance<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Single inheritance<\/h3>\n\n\n\n<p><strong>Syntax<\/strong><\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Class derived- class extends base-class<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;\/\/methods and fields<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<\/p>\n\n\n\n<p><strong>Example<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class school\n{  \nvoid name()\n{\nSystem.out.println(\"course...\");}  \n}  \nclass course extends school\n{  \nvoid place()\n{\nSystem.out.println(\"place...\");\n}  \n}  \nclass TestInheritance{  \npublic static void main(String args&#091;]){  \ncourse d = new course();  \nd.name();  \nd.place();  \n}\n}  \n\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Multilevel inheritance<\/h3>\n\n\n\n<p>Multilevel inheritance occurs when there is a chain of inheritance.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class school\n{  \nvoid name()\n{\nSystem.out.println(\"name\");\n}  \n}  \nclass course extends school\n{\nvoid place()\n{\nSystem.out.println(\"place\");\n}  \n}  \nclass primaryschool extends course\n{  \nvoid course()\n{\nSystem.out.println(\"course\");\n}\n} \nclass Testinheritance2\n{  \npublic static void main(String args&#091;])\n{  \nprimaryschool d=new primaryschool();\nd.course();\nd.place();\nd.name();\n}\n} \n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Hierarchical inheritance<\/h3>\n\n\n\n<p>&nbsp;Hierarchical inheritance occurs when two or more classes inherit the same class.<\/p>\n\n\n\n<p>Example course and primary school inherits the school class,so there is hierarchical inheritance.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class school\n{  \n\nvoid name()\n{\nSystem.out.println(\"name...\");\n}  \n}  \nclass course extends school\n{  \nvoid course()\n{\nSystem.out.println(\"course...\");\n}  \n}  \nclass primaryschool extends school\n{  \nvoid nursery()\n{\nSystem.out.println(\"nursery...\");\n}  \n}  \nclass TestInheritance3\n{  \npublic static void main(String args&#091;])\n{  \nprimaryschool d=new primaryschool();  \nd.name();  \n\/\/d.course();\nd.nursery();  \n }\n }  \n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">&nbsp;Hybrid inheritance<\/h3>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;Hybrid inheritance is a composition of two or more of the preceding types of inheritance.java does not support hybrid inheritance.it can achieve only through <strong><a href=\"https:\/\/www.programiz.com\/java-programming\/interfaces\">interface.<\/a><\/strong><\/p>\n\n\n\n<p>Example<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class School\n{\n}\nclass primaryschool extends School\n{\n}\nclass middleschool extends School\n{\n}\nclass highschool extends primaryschool  \n{\n    public static void main(String args&#091;])\n    {\n        School s = new School();\n        primaryschool p = new primaryschool();\n        middleschool m = new middleschool();\n  \n        System.out.println(s instanceof School);\n        System.out.println(p instanceof primaryschool);\n        System.out.println(m instanceof School);\n    }\n}\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>Hybrid inheritance in Java combines two or more inheritance types. Java uses defined classes in the software to reuse the code and modularize the software. Uncertainty avoided doing this. example: class B extends classes A and c, and A and c have the same method display ().&nbsp;<\/li><li>Java&#8217;s compiler is currently unable to choose which display method to inherit. Java forbids inheritance&nbsp;to prevent this from happening.<\/li><li>&nbsp;Multiple inheritance is not supported in Java, hybrid inheritance is&nbsp;not possible. This necessitates the usage of interfaces, just like multiple inheritances.<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Multiple inheritance<\/h3>\n\n\n\n<p>&nbsp;Multiple inheritance is not achieved through class but&nbsp;supported through interfaces.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Public interface interfaceA\n{\nPublic void hello();\n}\n Interface b.java\nPublic interface interface\n{\nPublic void hello();\n}\n<\/code><\/pre>\n\n\n\n<p>As seen in the example, we make an interface to extend one of these interfaces and to specify the same function.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>InterfaceC.java \n\nPublic interface interfaceC extends interfaceA,interfaceB\n{\nPublic void hello();\n}\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>Declaring a method with the concrete class will implement the interface which is totally acceptable to create an interfaces.<\/li><li>&nbsp;Hence, multiple inheritances in Java&nbsp;are not subject to form any ambiguity. Because of this, a Java class may implement a number of interfaces.<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Abstraction<\/h2>\n\n\n\n<p>&nbsp;&nbsp;An abstract class is one that has the keyword abstract in its declaration.<\/p>\n\n\n\n<p><strong>&nbsp;&nbsp;Syntax<\/strong><\/p>\n\n\n\n<p>Abstract class main()<\/p>\n\n\n\n<p>{<\/p>\n\n\n\n<p>Public abstract void&nbsp; hello()<\/p>\n\n\n\n<p>}<\/p>\n\n\n\n<p><strong>Declaring an Abstract class<\/strong><\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;Abstract class a()<\/p>\n\n\n\n<p><strong>Declaring an Abstract method<\/strong><\/p>\n\n\n\n<p>Abstract void hello()<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>abstract class school\n{  \n  abstract void name();  \n}  \nclass primary extends school\n{  \nvoid name()\n{\nSystem.out.println(\"good\");\n}  \npublic static void main(String args&#091;])\n{  \n school obj = new primary();  \n obj.name();  \n}  \n}  \n<\/code><\/pre>\n\n\n\n<p>Example 2:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>abstract class Bank\n{    \nabstract int getRateOfInterest();    \n}    \nclass SBI extends Bank\n{    \nint getRateOfInterest()\n{return 5;\n}    \n}    \nclass PNB extends Bank\n{    \nint getRateOfInterest()\n{\nreturn 6;\n}    \n}    \n    \nclass TestBank\n{    \npublic static void main(String args&#091;])\n{    \nBank b;  \nb=new SBI();  \nSystem.out.println(\"Rate of Interest is: \"+b.getRateOfInterest()+\" %\");    \nb=new PNB();  \nSystem.out.println(\"Rate of Interest is: \"+b.getRateOfInterest()+\" %\");    \n}\n}    \n<\/code><\/pre>\n\n\n\n<p><strong>&nbsp;Points to remember<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>An abstract method is declared as an abstract class but has no implementation.<\/li><li>A data member<\/li><li>&nbsp;abstract method<\/li><li>&nbsp;method body (non-abstract method),&nbsp;<\/li><li>function Object() { [native code] }<\/li><li>&nbsp;the main() method can&nbsp;found in an abstract class.<\/li><li>The interface can also implement in some way using the abstract class. In this situation, the user may not&nbsp;required to override every interface method.<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Encapsulation<\/h2>\n\n\n\n<p>Data encapsulation restricts&nbsp; the class fields and methods and modification by exterior classes. Moreover, this aids in data protection.<\/p>\n\n\n\n<p><strong>&nbsp;Example<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Public class school\nPrivate string Name;\nPublic string getName()\n{\nReturn name;\n}\nPublic void setName(String name)\n{\nthis.name=name\n}\n}\n<\/code><\/pre>\n\n\n\n<p>There are two methods in abstraction.<\/p>\n\n\n\n<p>&nbsp;\u201cread-only\u201d and \u201cwrite only\u201d called getter-setter methods in java. It provides control over the data.<\/p>\n\n\n\n<p>&nbsp;&nbsp;&nbsp;&nbsp;certainly, if you want to set the value of id which should be greater than 100 only, you can write the logic inside the setter method. <\/p>\n\n\n\n<p>You can write the logic not to store the negative numbers in the setter methods.<\/p>\n\n\n\n<p><strong>Example of getter and setter method in encapsulation<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>class school\n{ \nprivate int name;\nprivate int regno; \n    \/\/ getter method\n\tpublic int getregno() \n{\n        return this.regno=num;\n    }\n    \/\/ setter method\n\tpublic void name \n{\n        this.name;\n    }\n}\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Polymorphism<\/h2>\n\n\n\n<p>&nbsp;Here we have two types of polymorphism<\/p>\n\n\n\n<p>1. Runtime<\/p>\n\n\n\n<p>2. Compile time<\/p>\n\n\n\n<p><strong>Example for runtime polymorphism<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Public class school\nPublic void class ()\n{\nsystem.out.println(\u201cschool is good\u201d);\n}\n}\n<\/code><\/pre>\n\n\n\n<p>primary.java<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Class primary extends school\n{       \/\/override\/\/\nPublic void class()\n{\nsystem.out.println(\u201cnursery\u201d);\n}\nPublic static void main(string args&#091;])\n{\nSchool obj=new primary();\nobj.class();\n}\n}\n<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<p>It shows the output as nursery<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>Middle.java<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Class middle extends school\n{       \/\/override\/\/\nPublic void class()\n{\nsystem.out.println(\u201c6to8\u201d);\n}\nPublic static void main(string args&#091;])\n{\nSchool obj=new middle();\nobj.class();\n}\n}\n\n<\/code><\/pre>\n\n\n\n<p>It shows the output as 6to8<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>We defined the method sound() and have many implementations of it in the various sub-classes, as seen in the sample above.<\/p>\n\n\n\n<p>The example we provided below is a runtime polymorphism<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Class school\n{\nVoid demo (int a)\n{\nsystem.out.println(\u201ca:\u201d +a);\n}\nVoid demo (int a,int b)\n{ \nsystem.out.println(\u201ca and b:\u201d + a+\u201d,\u201d + b);\n}\nSecond demo (second a)\nsystem.out.println(\u201csecond a:\u201d+a);\nReturn a*a;\n}}\n\nClass method\n{\nPublic static void main(string args&#091;])\n{\n Method obj=new method();\nSecond result;\nobj.demo(2);\nobj.demo(2.4);\nresult=obj.demo(4,4);\nsystem.out.println(\u201coutput:\u201d + result);\n}\n}\n<\/code><\/pre>\n\n\n\n<p>There are three overloads of the method demo() in this case the first has one int parameter,&nbsp;the second has two int parameters,third has a double parameter.&nbsp;<\/p>\n\n\n\n<p>To specify the method we call the arguments to supply.Compile time polymorphism is the name given to the type of polymorphism that occurs when code is being built at runtime.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p><strong>OOPs concepts in Java.<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>OOPs is a concept created to overcome the problems of unstructured programming.<\/li><li>There are many languages that use oops like c,c++, and java.<\/li><li>Some of the advantages of using oops is the maintenance of complicated programs and reusability.<\/li><li>The Java Class is a component that controls the behavior and content of Java objects.<\/li><li>A Java object is a standalone element that has methods and properties to make a certain type of data usable.<\/li><li>Using techniques like inheritance, overriding, and augmenting, a class system enables the computer to define a new class (derived class) in terms of an existing class (superclass).<\/li><\/ul>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong>Best institute to learn Java for beginners.<\/strong><\/p>\n\n\n\n<p><a href=\"https:\/\/www.henryharvin.com\/blog\/core-java-interview-questions-and-answers\/\">Henry harvin<\/a><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Most respected industry experts with 11+ years of working experience.<\/li><li>Access E-learning access to tools and techniques,video content,assessment.<\/li><li>Find100%placement for 1 year post successful completion.<\/li><li>Get Hallmark Certification of Certified Java Developer from Henry Harvin\u00ae Govt of India recognized &amp; Award-Winning Institute,and showcase expertise.<\/li><\/ul>\n\n\n\n<p><strong><a href=\"https:\/\/www.henryharvin.com\/java-programming-for-beginners\">Learning benefits of Java<\/a><\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Understand the core Fundamentals of Java Programming language.<\/li><li>Acquire knowledge in Java Installation.<\/li><li>Learn Syntax to build useful applications.<\/li><li>Build necessary Tools used in Java applications.<\/li><li>Learn how Java Codes gets executed.<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-embed aligncenter is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe title=\"Java Tutorial #1: JDK, IDE and Hello World | Eclipse | Java Packages | Filipino | Tagalog\" width=\"720\" height=\"405\" src=\"https:\/\/www.youtube.com\/embed\/8HXqOHH2ocM?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><figcaption>Java for beginners<\/figcaption><\/figure>\n\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1679309758221\"><strong class=\"schema-faq-question\">FAQ of OOPs concepts in Java<br \/><strong>1. <\/strong>W<strong>hat is <\/strong>OOP<strong>s?<\/strong><br \/><\/strong> <p class=\"schema-faq-answer\">OOPs is a computer language used to design and build software with objects and classes. it relies on the concept of an object which is data, or attributes. an object is the basic unit of programming. each object has certain characteristics and exhibits different behavior.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1679309822797\"><strong class=\"schema-faq-question\"><strong>2. What are the OOPs concepts in java?<\/strong><\/strong> <p class=\"schema-faq-answer\">Objects<br \/>Classes<br \/>Abstraction<br \/>Inheritance<br \/>Encapsulation<br \/>Polymorphism<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1679309852327\"><strong class=\"schema-faq-question\"><strong>3. What is OOPs concept in java with an example?<\/strong><\/strong> <p class=\"schema-faq-answer\">OOPs, concepts in java explain objects,<br \/>\u00a0classes, abstraction, inheritance, polymorphism, and encapsulation with syntax and examples.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1679309960564\"><strong class=\"schema-faq-question\"><strong>4. What is the concept of OOPs?<\/strong><\/strong> <p class=\"schema-faq-answer\">Programming&#8217;s essential tenets\u00a0based on object-oriented programming (OOP) ideas. The goal of OOPs in Java is to increase code readability and reuse by defining Java programs.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1679310026845\"><strong class=\"schema-faq-question\"><strong>5. what are the benefits of OOPs in java?<\/strong><\/strong> <p class=\"schema-faq-answer\">The data-hiding principle assists programmers in creating secure programs.<br \/>We can drop code repetition and extend the use of existing classes by using inheritance.<br \/>It is simple to divide work in a project into objects.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1679310049040\"><strong class=\"schema-faq-question\"><strong>6. what is data encapsulation in OOPs?<\/strong><\/strong> <p class=\"schema-faq-answer\">\u00a0\u00a0Encapsulation is a data hiding\u00a0 used to protect data from the outside world.\u00a0\u00a0<br \/>Learn java programming course for beginners<\/p> <\/div> <\/div>\n\n\n\n<p><strong>Recommended for you<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\"><li><a href=\"https:\/\/www.javatpoint.com\/java-oops-concepts\">Java OOPs Concepts &#8211; Javatpoint<\/a><\/li><li><a href=\"https:\/\/www.mygreatlearning.com\/blog\/oops-concepts-in-java\/\">OOPs Concepts in Java ( Updated 2023) | Great Learning (mygreatlearning.com)<\/a><\/li><\/ol>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp;In this blog, we will go over the fundamentals of OOPs concepts in Java. OOPs is a language given to&#8230;<\/p>\n","protected":false},"author":959,"featured_media":157216,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_kad_post_classname":"","two_page_speed":[],"footnotes":""},"categories":[18655],"tags":[],"class_list":["post-155214","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-java"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>OOPs concepts in Java With Examples<\/title>\n<meta name=\"description\" content=\"OOPs concepts in Java With Examples: The goal of OOPs in Java is to increase code readability and reuse by defining Java programs.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.henryharvin.com\/blog\/oops-concepts-in-java-with-examples\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"OOPs concepts in Java With Examples\" \/>\n<meta property=\"og:description\" content=\"OOPs concepts in Java With Examples: The goal of OOPs in Java is to increase code readability and reuse by defining Java programs.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.henryharvin.com\/blog\/oops-concepts-in-java-with-examples\/\" \/>\n<meta property=\"og:site_name\" content=\"Henry Harvin Blog\" \/>\n<meta property=\"article:published_time\" content=\"2023-04-01T08:27:56+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-04-06T07:08:36+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/hh-certificates.sgp1.digitaloceanspaces.com\/blog\/wp-content\/uploads\/2023\/04\/06070825\/pasted-image-0-18.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1600\" \/>\n\t<meta property=\"og:image:height\" content=\"1067\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Upasana\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@henryharvin_in\" \/>\n<meta name=\"twitter:site\" content=\"@henryharvin_in\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Upasana\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"12 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/oops-concepts-in-java-with-examples\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/oops-concepts-in-java-with-examples\\\/\"},\"author\":{\"name\":\"Upasana\",\"@id\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/#\\\/schema\\\/person\\\/c1cdc8575f1305d77f47128a1e6980e5\"},\"headline\":\"OOPs concepts in Java With Examples\",\"datePublished\":\"2023-04-01T08:27:56+00:00\",\"dateModified\":\"2023-04-06T07:08:36+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/oops-concepts-in-java-with-examples\\\/\"},\"wordCount\":2230,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/#\\\/schema\\\/person\\\/a86f96dfdfc6fa224445f6b651967094\"},\"image\":{\"@id\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/oops-concepts-in-java-with-examples\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/hh-certificates.sgp1.digitaloceanspaces.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/04\\\/06070825\\\/pasted-image-0-18.jpg\",\"articleSection\":[\"Java Blogs | Learn More About Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/oops-concepts-in-java-with-examples\\\/#respond\"]}]},{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/oops-concepts-in-java-with-examples\\\/\",\"url\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/oops-concepts-in-java-with-examples\\\/\",\"name\":\"OOPs concepts in Java With Examples\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/oops-concepts-in-java-with-examples\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/oops-concepts-in-java-with-examples\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/hh-certificates.sgp1.digitaloceanspaces.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/04\\\/06070825\\\/pasted-image-0-18.jpg\",\"datePublished\":\"2023-04-01T08:27:56+00:00\",\"dateModified\":\"2023-04-06T07:08:36+00:00\",\"description\":\"OOPs concepts in Java With Examples: The goal of OOPs in Java is to increase code readability and reuse by defining Java programs.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/oops-concepts-in-java-with-examples\\\/#breadcrumb\"},\"mainEntity\":[{\"@id\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/oops-concepts-in-java-with-examples\\\/#faq-question-1679309758221\"},{\"@id\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/oops-concepts-in-java-with-examples\\\/#faq-question-1679309822797\"},{\"@id\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/oops-concepts-in-java-with-examples\\\/#faq-question-1679309852327\"},{\"@id\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/oops-concepts-in-java-with-examples\\\/#faq-question-1679309960564\"},{\"@id\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/oops-concepts-in-java-with-examples\\\/#faq-question-1679310026845\"},{\"@id\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/oops-concepts-in-java-with-examples\\\/#faq-question-1679310049040\"}],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/oops-concepts-in-java-with-examples\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/oops-concepts-in-java-with-examples\\\/#primaryimage\",\"url\":\"https:\\\/\\\/hh-certificates.sgp1.digitaloceanspaces.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/04\\\/06070825\\\/pasted-image-0-18.jpg\",\"contentUrl\":\"https:\\\/\\\/hh-certificates.sgp1.digitaloceanspaces.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/04\\\/06070825\\\/pasted-image-0-18.jpg\",\"width\":1600,\"height\":1067},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/oops-concepts-in-java-with-examples\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java Blogs | Learn More About Java\",\"item\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/category\\\/java\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"OOPs concepts in Java With Examples\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/\",\"name\":\"Henry Harvin Blog\",\"description\":\"Latest Online Courses &amp; Certification Blogs\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/#\\\/schema\\\/person\\\/a86f96dfdfc6fa224445f6b651967094\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/#\\\/schema\\\/person\\\/a86f96dfdfc6fa224445f6b651967094\",\"name\":\"George L V\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/hh-certificates.sgp1.digitaloceanspaces.com\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/01\\\/19130846\\\/cropped-Henry-harvin-logo-1.png\",\"url\":\"https:\\\/\\\/hh-certificates.sgp1.digitaloceanspaces.com\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/01\\\/19130846\\\/cropped-Henry-harvin-logo-1.png\",\"contentUrl\":\"https:\\\/\\\/hh-certificates.sgp1.digitaloceanspaces.com\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/01\\\/19130846\\\/cropped-Henry-harvin-logo-1.png\",\"width\":445,\"height\":130,\"caption\":\"George L V\"},\"logo\":{\"@id\":\"https:\\\/\\\/hh-certificates.sgp1.digitaloceanspaces.com\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/01\\\/19130846\\\/cropped-Henry-harvin-logo-1.png\"},\"description\":\"George is an expert communicator. As a coordinator, senior language instructor, center head and a content writer the basic requirement at the DNA level was the same \u2013 effective communication. He discovered early in life that quality of communication makes the difference between great results and mediocre outcomes. And thus, he developed his first forte: focus on the listener and tailor the message accordingly. As he progressed in his career, he realized that the most compelling stories communicate through multi-sensory messaging - a powerful combination of visual, verbal, and intuitive content.\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/#\\\/schema\\\/person\\\/c1cdc8575f1305d77f47128a1e6980e5\",\"name\":\"Upasana\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/hh-certificates.sgp1.digitaloceanspaces.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/05\\\/16092447\\\/IMG20230429110027-2-150x150.jpg\",\"url\":\"https:\\\/\\\/hh-certificates.sgp1.digitaloceanspaces.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/05\\\/16092447\\\/IMG20230429110027-2-150x150.jpg\",\"contentUrl\":\"https:\\\/\\\/hh-certificates.sgp1.digitaloceanspaces.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/05\\\/16092447\\\/IMG20230429110027-2-150x150.jpg\",\"caption\":\"Upasana\"},\"description\":\"i am a dedicated professional with a passion for content writing. She holds a graduate degree from VIT University and has recently embarked on a career transition from teaching to content creation. With two years of experience as a middle school teacher, Upasana brings her strong communication and instructional skills to the field of content writing.\",\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/upasana-s-443291170\\\/\"],\"url\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/author\\\/upassri-93gmail-com\\\/\"},{\"@type\":\"Question\",\"@id\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/oops-concepts-in-java-with-examples\\\/#faq-question-1679309758221\",\"position\":1,\"url\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/oops-concepts-in-java-with-examples\\\/#faq-question-1679309758221\",\"name\":\"FAQ of OOPs concepts in Java 1. What is OOPs?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"OOPs is a computer language used to design and build software with objects and classes. it relies on the concept of an object which is data, or attributes. an object is the basic unit of programming. each object has certain characteristics and exhibits different behavior.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/oops-concepts-in-java-with-examples\\\/#faq-question-1679309822797\",\"position\":2,\"url\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/oops-concepts-in-java-with-examples\\\/#faq-question-1679309822797\",\"name\":\"2. What are the OOPs concepts in java?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Objects<br \\\/>Classes<br \\\/>Abstraction<br \\\/>Inheritance<br \\\/>Encapsulation<br \\\/>Polymorphism\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/oops-concepts-in-java-with-examples\\\/#faq-question-1679309852327\",\"position\":3,\"url\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/oops-concepts-in-java-with-examples\\\/#faq-question-1679309852327\",\"name\":\"3. What is OOPs concept in java with an example?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"OOPs, concepts in java explain objects,<br \\\/>\u00a0classes, abstraction, inheritance, polymorphism, and encapsulation with syntax and examples.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/oops-concepts-in-java-with-examples\\\/#faq-question-1679309960564\",\"position\":4,\"url\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/oops-concepts-in-java-with-examples\\\/#faq-question-1679309960564\",\"name\":\"4. What is the concept of OOPs?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Programming's essential tenets\u00a0based on object-oriented programming (OOP) ideas. The goal of OOPs in Java is to increase code readability and reuse by defining Java programs.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/oops-concepts-in-java-with-examples\\\/#faq-question-1679310026845\",\"position\":5,\"url\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/oops-concepts-in-java-with-examples\\\/#faq-question-1679310026845\",\"name\":\"5. what are the benefits of OOPs in java?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"The data-hiding principle assists programmers in creating secure programs.<br \\\/>We can drop code repetition and extend the use of existing classes by using inheritance.<br \\\/>It is simple to divide work in a project into objects.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/oops-concepts-in-java-with-examples\\\/#faq-question-1679310049040\",\"position\":6,\"url\":\"https:\\\/\\\/www.henryharvin.com\\\/blog\\\/oops-concepts-in-java-with-examples\\\/#faq-question-1679310049040\",\"name\":\"6. what is data encapsulation in OOPs?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"\u00a0\u00a0Encapsulation is a data hiding\u00a0 used to protect data from the outside world.\u00a0\u00a0<br \\\/>Learn java programming course for beginners\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"OOPs concepts in Java With Examples","description":"OOPs concepts in Java With Examples: The goal of OOPs in Java is to increase code readability and reuse by defining Java programs.","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:\/\/www.henryharvin.com\/blog\/oops-concepts-in-java-with-examples\/","og_locale":"en_US","og_type":"article","og_title":"OOPs concepts in Java With Examples","og_description":"OOPs concepts in Java With Examples: The goal of OOPs in Java is to increase code readability and reuse by defining Java programs.","og_url":"https:\/\/www.henryharvin.com\/blog\/oops-concepts-in-java-with-examples\/","og_site_name":"Henry Harvin Blog","article_published_time":"2023-04-01T08:27:56+00:00","article_modified_time":"2023-04-06T07:08:36+00:00","og_image":[{"width":1600,"height":1067,"url":"https:\/\/hh-certificates.sgp1.digitaloceanspaces.com\/blog\/wp-content\/uploads\/2023\/04\/06070825\/pasted-image-0-18.jpg","type":"image\/jpeg"}],"author":"Upasana","twitter_card":"summary_large_image","twitter_creator":"@henryharvin_in","twitter_site":"@henryharvin_in","twitter_misc":{"Written by":"Upasana","Est. reading time":"12 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.henryharvin.com\/blog\/oops-concepts-in-java-with-examples\/#article","isPartOf":{"@id":"https:\/\/www.henryharvin.com\/blog\/oops-concepts-in-java-with-examples\/"},"author":{"name":"Upasana","@id":"https:\/\/www.henryharvin.com\/blog\/#\/schema\/person\/c1cdc8575f1305d77f47128a1e6980e5"},"headline":"OOPs concepts in Java With Examples","datePublished":"2023-04-01T08:27:56+00:00","dateModified":"2023-04-06T07:08:36+00:00","mainEntityOfPage":{"@id":"https:\/\/www.henryharvin.com\/blog\/oops-concepts-in-java-with-examples\/"},"wordCount":2230,"commentCount":0,"publisher":{"@id":"https:\/\/www.henryharvin.com\/blog\/#\/schema\/person\/a86f96dfdfc6fa224445f6b651967094"},"image":{"@id":"https:\/\/www.henryharvin.com\/blog\/oops-concepts-in-java-with-examples\/#primaryimage"},"thumbnailUrl":"https:\/\/hh-certificates.sgp1.digitaloceanspaces.com\/blog\/wp-content\/uploads\/2023\/04\/06070825\/pasted-image-0-18.jpg","articleSection":["Java Blogs | Learn More About Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.henryharvin.com\/blog\/oops-concepts-in-java-with-examples\/#respond"]}]},{"@type":["WebPage","FAQPage"],"@id":"https:\/\/www.henryharvin.com\/blog\/oops-concepts-in-java-with-examples\/","url":"https:\/\/www.henryharvin.com\/blog\/oops-concepts-in-java-with-examples\/","name":"OOPs concepts in Java With Examples","isPartOf":{"@id":"https:\/\/www.henryharvin.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.henryharvin.com\/blog\/oops-concepts-in-java-with-examples\/#primaryimage"},"image":{"@id":"https:\/\/www.henryharvin.com\/blog\/oops-concepts-in-java-with-examples\/#primaryimage"},"thumbnailUrl":"https:\/\/hh-certificates.sgp1.digitaloceanspaces.com\/blog\/wp-content\/uploads\/2023\/04\/06070825\/pasted-image-0-18.jpg","datePublished":"2023-04-01T08:27:56+00:00","dateModified":"2023-04-06T07:08:36+00:00","description":"OOPs concepts in Java With Examples: The goal of OOPs in Java is to increase code readability and reuse by defining Java programs.","breadcrumb":{"@id":"https:\/\/www.henryharvin.com\/blog\/oops-concepts-in-java-with-examples\/#breadcrumb"},"mainEntity":[{"@id":"https:\/\/www.henryharvin.com\/blog\/oops-concepts-in-java-with-examples\/#faq-question-1679309758221"},{"@id":"https:\/\/www.henryharvin.com\/blog\/oops-concepts-in-java-with-examples\/#faq-question-1679309822797"},{"@id":"https:\/\/www.henryharvin.com\/blog\/oops-concepts-in-java-with-examples\/#faq-question-1679309852327"},{"@id":"https:\/\/www.henryharvin.com\/blog\/oops-concepts-in-java-with-examples\/#faq-question-1679309960564"},{"@id":"https:\/\/www.henryharvin.com\/blog\/oops-concepts-in-java-with-examples\/#faq-question-1679310026845"},{"@id":"https:\/\/www.henryharvin.com\/blog\/oops-concepts-in-java-with-examples\/#faq-question-1679310049040"}],"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.henryharvin.com\/blog\/oops-concepts-in-java-with-examples\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.henryharvin.com\/blog\/oops-concepts-in-java-with-examples\/#primaryimage","url":"https:\/\/hh-certificates.sgp1.digitaloceanspaces.com\/blog\/wp-content\/uploads\/2023\/04\/06070825\/pasted-image-0-18.jpg","contentUrl":"https:\/\/hh-certificates.sgp1.digitaloceanspaces.com\/blog\/wp-content\/uploads\/2023\/04\/06070825\/pasted-image-0-18.jpg","width":1600,"height":1067},{"@type":"BreadcrumbList","@id":"https:\/\/www.henryharvin.com\/blog\/oops-concepts-in-java-with-examples\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.henryharvin.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Java Blogs | Learn More About Java","item":"https:\/\/www.henryharvin.com\/blog\/category\/java\/"},{"@type":"ListItem","position":3,"name":"OOPs concepts in Java With Examples"}]},{"@type":"WebSite","@id":"https:\/\/www.henryharvin.com\/blog\/#website","url":"https:\/\/www.henryharvin.com\/blog\/","name":"Henry Harvin Blog","description":"Latest Online Courses &amp; Certification Blogs","publisher":{"@id":"https:\/\/www.henryharvin.com\/blog\/#\/schema\/person\/a86f96dfdfc6fa224445f6b651967094"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.henryharvin.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.henryharvin.com\/blog\/#\/schema\/person\/a86f96dfdfc6fa224445f6b651967094","name":"George L V","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/hh-certificates.sgp1.digitaloceanspaces.com\/blog\/wp-content\/uploads\/2025\/01\/19130846\/cropped-Henry-harvin-logo-1.png","url":"https:\/\/hh-certificates.sgp1.digitaloceanspaces.com\/blog\/wp-content\/uploads\/2025\/01\/19130846\/cropped-Henry-harvin-logo-1.png","contentUrl":"https:\/\/hh-certificates.sgp1.digitaloceanspaces.com\/blog\/wp-content\/uploads\/2025\/01\/19130846\/cropped-Henry-harvin-logo-1.png","width":445,"height":130,"caption":"George L V"},"logo":{"@id":"https:\/\/hh-certificates.sgp1.digitaloceanspaces.com\/blog\/wp-content\/uploads\/2025\/01\/19130846\/cropped-Henry-harvin-logo-1.png"},"description":"George is an expert communicator. As a coordinator, senior language instructor, center head and a content writer the basic requirement at the DNA level was the same \u2013 effective communication. He discovered early in life that quality of communication makes the difference between great results and mediocre outcomes. And thus, he developed his first forte: focus on the listener and tailor the message accordingly. As he progressed in his career, he realized that the most compelling stories communicate through multi-sensory messaging - a powerful combination of visual, verbal, and intuitive content."},{"@type":"Person","@id":"https:\/\/www.henryharvin.com\/blog\/#\/schema\/person\/c1cdc8575f1305d77f47128a1e6980e5","name":"Upasana","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/hh-certificates.sgp1.digitaloceanspaces.com\/blog\/wp-content\/uploads\/2023\/05\/16092447\/IMG20230429110027-2-150x150.jpg","url":"https:\/\/hh-certificates.sgp1.digitaloceanspaces.com\/blog\/wp-content\/uploads\/2023\/05\/16092447\/IMG20230429110027-2-150x150.jpg","contentUrl":"https:\/\/hh-certificates.sgp1.digitaloceanspaces.com\/blog\/wp-content\/uploads\/2023\/05\/16092447\/IMG20230429110027-2-150x150.jpg","caption":"Upasana"},"description":"i am a dedicated professional with a passion for content writing. She holds a graduate degree from VIT University and has recently embarked on a career transition from teaching to content creation. With two years of experience as a middle school teacher, Upasana brings her strong communication and instructional skills to the field of content writing.","sameAs":["https:\/\/www.linkedin.com\/in\/upasana-s-443291170\/"],"url":"https:\/\/www.henryharvin.com\/blog\/author\/upassri-93gmail-com\/"},{"@type":"Question","@id":"https:\/\/www.henryharvin.com\/blog\/oops-concepts-in-java-with-examples\/#faq-question-1679309758221","position":1,"url":"https:\/\/www.henryharvin.com\/blog\/oops-concepts-in-java-with-examples\/#faq-question-1679309758221","name":"FAQ of OOPs concepts in Java 1. What is OOPs?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"OOPs is a computer language used to design and build software with objects and classes. it relies on the concept of an object which is data, or attributes. an object is the basic unit of programming. each object has certain characteristics and exhibits different behavior.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.henryharvin.com\/blog\/oops-concepts-in-java-with-examples\/#faq-question-1679309822797","position":2,"url":"https:\/\/www.henryharvin.com\/blog\/oops-concepts-in-java-with-examples\/#faq-question-1679309822797","name":"2. What are the OOPs concepts in java?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Objects<br \/>Classes<br \/>Abstraction<br \/>Inheritance<br \/>Encapsulation<br \/>Polymorphism","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.henryharvin.com\/blog\/oops-concepts-in-java-with-examples\/#faq-question-1679309852327","position":3,"url":"https:\/\/www.henryharvin.com\/blog\/oops-concepts-in-java-with-examples\/#faq-question-1679309852327","name":"3. What is OOPs concept in java with an example?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"OOPs, concepts in java explain objects,<br \/>\u00a0classes, abstraction, inheritance, polymorphism, and encapsulation with syntax and examples.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.henryharvin.com\/blog\/oops-concepts-in-java-with-examples\/#faq-question-1679309960564","position":4,"url":"https:\/\/www.henryharvin.com\/blog\/oops-concepts-in-java-with-examples\/#faq-question-1679309960564","name":"4. What is the concept of OOPs?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Programming's essential tenets\u00a0based on object-oriented programming (OOP) ideas. The goal of OOPs in Java is to increase code readability and reuse by defining Java programs.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.henryharvin.com\/blog\/oops-concepts-in-java-with-examples\/#faq-question-1679310026845","position":5,"url":"https:\/\/www.henryharvin.com\/blog\/oops-concepts-in-java-with-examples\/#faq-question-1679310026845","name":"5. what are the benefits of OOPs in java?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"The data-hiding principle assists programmers in creating secure programs.<br \/>We can drop code repetition and extend the use of existing classes by using inheritance.<br \/>It is simple to divide work in a project into objects.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/www.henryharvin.com\/blog\/oops-concepts-in-java-with-examples\/#faq-question-1679310049040","position":6,"url":"https:\/\/www.henryharvin.com\/blog\/oops-concepts-in-java-with-examples\/#faq-question-1679310049040","name":"6. what is data encapsulation in OOPs?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"\u00a0\u00a0Encapsulation is a data hiding\u00a0 used to protect data from the outside world.\u00a0\u00a0<br \/>Learn java programming course for beginners","inLanguage":"en-US"},"inLanguage":"en-US"}]}},"views":1374,"_links":{"self":[{"href":"https:\/\/www.henryharvin.com\/blog\/wp-json\/wp\/v2\/posts\/155214","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.henryharvin.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.henryharvin.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.henryharvin.com\/blog\/wp-json\/wp\/v2\/users\/959"}],"replies":[{"embeddable":true,"href":"https:\/\/www.henryharvin.com\/blog\/wp-json\/wp\/v2\/comments?post=155214"}],"version-history":[{"count":0,"href":"https:\/\/www.henryharvin.com\/blog\/wp-json\/wp\/v2\/posts\/155214\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.henryharvin.com\/blog\/wp-json\/wp\/v2\/media\/157216"}],"wp:attachment":[{"href":"https:\/\/www.henryharvin.com\/blog\/wp-json\/wp\/v2\/media?parent=155214"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.henryharvin.com\/blog\/wp-json\/wp\/v2\/categories?post=155214"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.henryharvin.com\/blog\/wp-json\/wp\/v2\/tags?post=155214"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}