├── .DS_Store
├── .idea
├── .gitignore
├── vcs.xml
├── modules.xml
├── misc.xml
└── uiDesigner.xml
├── src
├── .DS_Store
├── inheritance
│ ├── .DS_Store
│ ├── parent.java
│ ├── child.java
│ └── main.java
├── interfaces
│ ├── animaldata.java
│ ├── data.java
│ ├── dog.java
│ └── animal.java
├── methordOverriding
│ ├── daughter.java
│ └── mother.java
├── variables
│ └── variablesTypes.java
├── Object
│ └── personalData.java
├── superKeyword
│ ├── son.java
│ └── father.java
├── abstracts
│ ├── samsung.java
│ ├── iphone.java
│ └── phone.java
├── accessModifiers
│ └── accessModifiers.java
├── ConstructorOverloading
│ └── constructorOverloading.java
├── finalKeyword.java
├── methordOverloading
│ └── MethodOverloading.java
├── encapsulation
│ └── person.java
└── Main.java
├── out
└── production
│ └── oop
│ ├── Bike.class
│ ├── Dog.class
│ ├── ICT.class
│ ├── Main.class
│ ├── test.class
│ ├── Animal.class
│ ├── BabyDog.class
│ ├── yamaha.class
│ ├── finalKeyword.class
│ ├── interfaces
│ ├── dog.class
│ ├── animal.class
│ ├── data.class
│ └── animaldata.class
│ ├── abstracts
│ ├── iphone.class
│ ├── phone.class
│ └── samsung.class
│ ├── inheritance
│ ├── child.class
│ ├── main.class
│ └── parent.class
│ ├── superKeyword
│ ├── son.class
│ └── father.class
│ ├── Object
│ └── personalData.class
│ ├── encapsulation
│ └── person.class
│ ├── methordOverriding
│ ├── mother.class
│ └── daughter.class
│ ├── variables
│ └── variablesTypes.class
│ ├── accessModifiers
│ └── accessModifiers.class
│ ├── methordOverloading
│ └── MethodOverloading.class
│ └── ConstructorOverloading
│ └── constructorOverloading.class
├── oop.iml
├── LICENSE
└── README.md
/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sanchithaudana/java-OOP/HEAD/.DS_Store
--------------------------------------------------------------------------------
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/src/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sanchithaudana/java-OOP/HEAD/src/.DS_Store
--------------------------------------------------------------------------------
/src/inheritance/.DS_Store:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sanchithaudana/java-OOP/HEAD/src/inheritance/.DS_Store
--------------------------------------------------------------------------------
/out/production/oop/Bike.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sanchithaudana/java-OOP/HEAD/out/production/oop/Bike.class
--------------------------------------------------------------------------------
/out/production/oop/Dog.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sanchithaudana/java-OOP/HEAD/out/production/oop/Dog.class
--------------------------------------------------------------------------------
/out/production/oop/ICT.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sanchithaudana/java-OOP/HEAD/out/production/oop/ICT.class
--------------------------------------------------------------------------------
/out/production/oop/Main.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sanchithaudana/java-OOP/HEAD/out/production/oop/Main.class
--------------------------------------------------------------------------------
/out/production/oop/test.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sanchithaudana/java-OOP/HEAD/out/production/oop/test.class
--------------------------------------------------------------------------------
/out/production/oop/Animal.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sanchithaudana/java-OOP/HEAD/out/production/oop/Animal.class
--------------------------------------------------------------------------------
/out/production/oop/BabyDog.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sanchithaudana/java-OOP/HEAD/out/production/oop/BabyDog.class
--------------------------------------------------------------------------------
/out/production/oop/yamaha.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sanchithaudana/java-OOP/HEAD/out/production/oop/yamaha.class
--------------------------------------------------------------------------------
/out/production/oop/finalKeyword.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sanchithaudana/java-OOP/HEAD/out/production/oop/finalKeyword.class
--------------------------------------------------------------------------------
/out/production/oop/interfaces/dog.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sanchithaudana/java-OOP/HEAD/out/production/oop/interfaces/dog.class
--------------------------------------------------------------------------------
/out/production/oop/abstracts/iphone.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sanchithaudana/java-OOP/HEAD/out/production/oop/abstracts/iphone.class
--------------------------------------------------------------------------------
/out/production/oop/abstracts/phone.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sanchithaudana/java-OOP/HEAD/out/production/oop/abstracts/phone.class
--------------------------------------------------------------------------------
/out/production/oop/abstracts/samsung.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sanchithaudana/java-OOP/HEAD/out/production/oop/abstracts/samsung.class
--------------------------------------------------------------------------------
/out/production/oop/inheritance/child.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sanchithaudana/java-OOP/HEAD/out/production/oop/inheritance/child.class
--------------------------------------------------------------------------------
/out/production/oop/inheritance/main.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sanchithaudana/java-OOP/HEAD/out/production/oop/inheritance/main.class
--------------------------------------------------------------------------------
/out/production/oop/interfaces/animal.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sanchithaudana/java-OOP/HEAD/out/production/oop/interfaces/animal.class
--------------------------------------------------------------------------------
/out/production/oop/interfaces/data.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sanchithaudana/java-OOP/HEAD/out/production/oop/interfaces/data.class
--------------------------------------------------------------------------------
/out/production/oop/superKeyword/son.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sanchithaudana/java-OOP/HEAD/out/production/oop/superKeyword/son.class
--------------------------------------------------------------------------------
/out/production/oop/Object/personalData.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sanchithaudana/java-OOP/HEAD/out/production/oop/Object/personalData.class
--------------------------------------------------------------------------------
/out/production/oop/inheritance/parent.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sanchithaudana/java-OOP/HEAD/out/production/oop/inheritance/parent.class
--------------------------------------------------------------------------------
/out/production/oop/superKeyword/father.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sanchithaudana/java-OOP/HEAD/out/production/oop/superKeyword/father.class
--------------------------------------------------------------------------------
/src/interfaces/animaldata.java:
--------------------------------------------------------------------------------
1 | package interfaces;
2 |
3 | public interface animaldata {
4 | void run();
5 | void sleep();
6 |
7 | }
8 |
--------------------------------------------------------------------------------
/out/production/oop/encapsulation/person.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sanchithaudana/java-OOP/HEAD/out/production/oop/encapsulation/person.class
--------------------------------------------------------------------------------
/out/production/oop/interfaces/animaldata.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sanchithaudana/java-OOP/HEAD/out/production/oop/interfaces/animaldata.class
--------------------------------------------------------------------------------
/out/production/oop/methordOverriding/mother.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sanchithaudana/java-OOP/HEAD/out/production/oop/methordOverriding/mother.class
--------------------------------------------------------------------------------
/out/production/oop/variables/variablesTypes.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sanchithaudana/java-OOP/HEAD/out/production/oop/variables/variablesTypes.class
--------------------------------------------------------------------------------
/out/production/oop/methordOverriding/daughter.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sanchithaudana/java-OOP/HEAD/out/production/oop/methordOverriding/daughter.class
--------------------------------------------------------------------------------
/out/production/oop/accessModifiers/accessModifiers.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sanchithaudana/java-OOP/HEAD/out/production/oop/accessModifiers/accessModifiers.class
--------------------------------------------------------------------------------
/out/production/oop/methordOverloading/MethodOverloading.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sanchithaudana/java-OOP/HEAD/out/production/oop/methordOverloading/MethodOverloading.class
--------------------------------------------------------------------------------
/out/production/oop/ConstructorOverloading/constructorOverloading.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/sanchithaudana/java-OOP/HEAD/out/production/oop/ConstructorOverloading/constructorOverloading.class
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/src/methordOverriding/daughter.java:
--------------------------------------------------------------------------------
1 | package methordOverriding;
2 |
3 | public class daughter extends mother{
4 |
5 | @Override
6 | public void phone(){
7 | System.out.println("techno spark");
8 | }
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/src/methordOverriding/mother.java:
--------------------------------------------------------------------------------
1 | package methordOverriding;
2 |
3 | public class mother {
4 |
5 | public void phone(){
6 | System.out.println("samsung");
7 | }
8 |
9 | public int id(){
10 | System.out.println(1980);
11 | return 0;
12 | }
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/src/inheritance/parent.java:
--------------------------------------------------------------------------------
1 | package inheritance;
2 |
3 | public class parent {
4 |
5 | // inheritance - mainly using sub classes and super class
6 | protected int height;
7 | protected int width;
8 |
9 | public void sing(){
10 | System.out.println("sing a song");
11 | }
12 |
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/src/interfaces/data.java:
--------------------------------------------------------------------------------
1 | package interfaces;
2 |
3 | public interface data {
4 | void data();
5 | default void data1(){
6 | System.out.println("default function in interface");
7 | }
8 |
9 | static void data2(){
10 | System.out.println("static function in interface");
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/variables/variablesTypes.java:
--------------------------------------------------------------------------------
1 | package variables;
2 |
3 | public class variablesTypes {
4 |
5 | String name; // instant variable
6 |
7 | static String dep; // static variable
8 |
9 | public void school(){
10 |
11 | int marks; // local variable
12 |
13 | }
14 |
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/src/inheritance/child.java:
--------------------------------------------------------------------------------
1 | package inheritance;
2 |
3 | public class child extends parent{
4 |
5 | // inheritance in not support, if you set a class using "final" keyword
6 | // multiple inheritance is not allowed in java
7 |
8 | int age;
9 | public void write(){
10 | System.out.println("write letters");
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/Object/personalData.java:
--------------------------------------------------------------------------------
1 | package Object;
2 |
3 | public class personalData {
4 |
5 | // in the class you firstly create methods and you can develop towards
6 |
7 | public personalData() { // default constructor
8 | }
9 |
10 | public void name(){
11 | System.out.println("Sanchitha");
12 | }
13 |
14 |
15 |
16 |
17 | }
18 |
--------------------------------------------------------------------------------
/src/inheritance/main.java:
--------------------------------------------------------------------------------
1 | package inheritance;
2 |
3 | public class main {
4 |
5 | public void checker(){
6 |
7 | child c = new child();
8 |
9 | c.write();
10 | c.sing(); // inherit method parent to child
11 |
12 | c.height = 23; // inherit variable parent to child
13 | c.age = 18;
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 | }
24 |
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/src/superKeyword/son.java:
--------------------------------------------------------------------------------
1 | package superKeyword;
2 |
3 | public class son extends father {
4 |
5 | // default constructor
6 | public son() {
7 | super();
8 | System.out.println("default constructor in son class");
9 | }
10 |
11 | // parameterized constructor
12 | public son(int a){
13 | super(5);
14 | System.out.println("parameterized constructor in son class");
15 | }
16 |
17 | }
18 |
19 |
20 |
--------------------------------------------------------------------------------
/src/abstracts/samsung.java:
--------------------------------------------------------------------------------
1 | package abstracts;
2 |
3 | public class samsung extends phone{
4 |
5 | @Override
6 | public void call() {
7 | System.out.println("in samsung call");
8 | }
9 |
10 | @Override
11 | public void sleep(){
12 | System.out.println("in samsung sleep");
13 | }
14 |
15 | @Override
16 | public void vibrate(){
17 | System.out.println("in samsung vibrate");
18 | }
19 |
20 |
21 | }
22 |
--------------------------------------------------------------------------------
/oop.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/src/abstracts/iphone.java:
--------------------------------------------------------------------------------
1 | package abstracts;
2 |
3 | public class iphone extends phone{
4 |
5 | @Override
6 | public void call() {
7 | System.out.println("iphone call");
8 | }
9 |
10 | @Override
11 | public void sleep() {
12 | System.out.println("iphone sleeping");
13 | }
14 |
15 | @Override
16 | public void vibrate() {
17 | System.out.println("iphone vibrate");
18 | }
19 |
20 |
21 |
22 |
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/src/superKeyword/father.java:
--------------------------------------------------------------------------------
1 | package superKeyword;
2 |
3 | public class father {
4 |
5 | // default constructor
6 | public father(){
7 | System.out.println("default constructor in father class");
8 | }
9 |
10 | // parameterized constructor
11 | public father(int a){
12 | System.out.println("parameterized constructor in father class" + a );
13 | }
14 |
15 |
16 | // you can create methods after creating constructors
17 |
18 |
19 |
20 |
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/src/accessModifiers/accessModifiers.java:
--------------------------------------------------------------------------------
1 | package accessModifiers;
2 |
3 | public class accessModifiers {
4 |
5 | // default
6 | // using in same package
7 | int a;
8 | int b;
9 |
10 | // private
11 | // using in relevant java class only
12 | private String name;
13 | private String password;
14 |
15 | // public
16 | // using in any where
17 | public int summer;
18 | public String som;
19 |
20 | // protected
21 | // using in same package and sub classes (using inherited classes)
22 | protected int id;
23 | protected String age;
24 |
25 |
26 |
27 |
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/src/abstracts/phone.java:
--------------------------------------------------------------------------------
1 | package abstracts;
2 |
3 | public abstract class phone {
4 | // abstract method has not method body
5 | // we can not create object relevant abstract classes
6 | // can include abstract methods or non-abstract methods
7 | // if we need to use abstract methods, so we must inherit abstract class to other java class
8 |
9 | public abstract void call(); // abstract method
10 | public abstract void sleep();
11 | public abstract void vibrate();
12 | public void talk(){ // non-abstract method
13 | System.out.println("can call");
14 | }
15 |
16 |
17 |
18 |
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/src/interfaces/dog.java:
--------------------------------------------------------------------------------
1 | package interfaces;
2 |
3 | public class dog implements animal,animaldata,data{ // multiple implements
4 |
5 | @Override
6 | public void data() {
7 | System.out.println("Data");
8 | }
9 |
10 | @Override
11 | public void run(){
12 | System.out.println("in multiple implements");
13 | }
14 |
15 | @Override
16 | public void sleep() {
17 | System.out.println("sleeping");
18 | }
19 |
20 | @Override
21 | public void eat() {
22 | System.out.println("eating");
23 | }
24 |
25 | @Override
26 | public void getup(){
27 | System.out.println("get up");
28 | }
29 |
30 | }
31 |
32 |
--------------------------------------------------------------------------------
/src/ConstructorOverloading/constructorOverloading.java:
--------------------------------------------------------------------------------
1 | package ConstructorOverloading;
2 |
3 | public class constructorOverloading {
4 |
5 | String name;
6 | int age;
7 |
8 | public constructorOverloading() {
9 | }
10 |
11 | public constructorOverloading(String name) {
12 | this.name = name;
13 | }
14 |
15 | public constructorOverloading(String name, int age) {
16 | this.name = name;
17 | this.age = age;
18 | }
19 |
20 |
21 | // in above code set have three types of constructors. the first type is the default constructor
22 | // other two constructors have different parameters
23 | // this is the constructors overloading method in OOP concept in java
24 |
25 |
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/src/finalKeyword.java:
--------------------------------------------------------------------------------
1 | public class finalKeyword {
2 |
3 | // we can use final keyword in a variable , method and class
4 |
5 | // --> in final variable
6 | // in final variable we can not change the value in future
7 | // we can assign final variable only one time using constructor
8 |
9 | // --> in final method
10 | // we can inherit final methods
11 | // we can not override final methods
12 |
13 | // --> in final class
14 | // we can not inherit final class
15 |
16 | final int race = 10; // final instant variable
17 | int laps;
18 |
19 | // final method
20 | public final void school(){
21 | System.out.println("this is a final method");
22 | }
23 |
24 |
25 |
26 |
27 | }
28 |
--------------------------------------------------------------------------------
/src/methordOverloading/MethodOverloading.java:
--------------------------------------------------------------------------------
1 | package methordOverloading;
2 |
3 | public class MethodOverloading {
4 |
5 | int year;
6 | int month;
7 | int day;
8 |
9 | public void age(){
10 | System.out.println("non parameters");
11 | }
12 |
13 | public void age(int year){
14 | System.out.println("one parameter");
15 | }
16 |
17 | public void age(int month,int day){
18 | System.out.println("two parameters");
19 | }
20 |
21 | public void age(int year, int month, int day){
22 | System.out.println("three parameters");
23 | }
24 |
25 | // in this all methods named as 'age' but they have different types og parameters patters.
26 | // so we can say this is the method overloading concept in OOP concept
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/src/interfaces/animal.java:
--------------------------------------------------------------------------------
1 | package interfaces;
2 |
3 | public interface animal {
4 |
5 | // by default in interface methods are abstract and public
6 | // abstract method have not a body
7 | // interface can not create an object
8 | // interface not have constructor
9 | // we can not inherit interface using extends keyword , but we use implements keyword to inherit
10 | // can not include non-abstract methods
11 | // can use multiple implements
12 |
13 | void sleep();
14 | void eat();
15 | void getup();
16 |
17 | // we can give body part in only default and static methods
18 | default void newmethod(){
19 | System.out.println("in default");
20 | }
21 |
22 | static void newmethod1(){
23 | System.out.println("in static");
24 | }
25 |
26 |
27 |
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2023 Sanchitha Udana Wijesundara
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/src/encapsulation/person.java:
--------------------------------------------------------------------------------
1 | package encapsulation;
2 |
3 | public class person {
4 |
5 | private int id;
6 | private String name;
7 | private String department;
8 |
9 | // getters : used to get the data from private variables
10 | // setters : used to set the data to private variables
11 |
12 | // setter of id
13 | public void setId(int id){
14 | this.id = id;
15 | }
16 | // getter of id
17 | public int getId(){
18 | return id;
19 | }
20 | // getter of name
21 | public String getName() {
22 | return name;
23 | }
24 | // setter of name
25 | public void setName(String name) {
26 | this.name = name;
27 | }
28 | // getter of department
29 | public String getDepartment() {
30 | return department;
31 | }
32 | // setter of department
33 | public void setDepartment(String department) {
34 | this.department = department;
35 | }
36 |
37 | private int passcode;
38 |
39 | public void setPasscode(int passcode){
40 | this.passcode = passcode;
41 | }
42 |
43 | public int getPasscode(){
44 | return passcode;
45 | }
46 |
47 |
48 | private int mark;
49 |
50 | public int getMark() {
51 | return mark;
52 | }
53 |
54 | public void setMark(int mark) {
55 | this.mark = mark;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # You can refer to the "src" file Contents with the "main.java" file (the main.java file is the main file to interact with others)
2 |
3 |
4 | ## java OOP Concept
5 |
6 | 
7 |
8 |
9 |
10 |
11 |
12 | Languages and Tools:
13 |
14 |
15 | OOPs (Object-Oriented Programming System)
16 |
17 | Object-Oriented Programming (OOP) is a programming paradigm centered around the concept of "objects," which can contain data and methods. It is designed to model real-world entities and their interactions in a programmatic way. Here are the key concepts of OOP:
18 |
19 | 1. **Classes and Objects**:
20 | - **Class**: A blueprint for creating objects. It defines the properties (attributes) and behaviors (methods) that the objects created from the class can have.
21 | - **Object**: An instance of a class. It represents a specific example of a class with actual values for its attributes.
22 |
23 | 2. **Encapsulation**:
24 | - Encapsulation is the practice of bundling the data (attributes) and methods (functions) that operate on the data into a single unit called an object. It restricts direct access to some of an object's components, which is a means of preventing unintended interference and misuse of the data.
25 |
26 | 3. **Inheritance**:
27 | - Inheritance is a mechanism in which one class (called a subclass or derived class) inherits the properties and behaviors of another class (called a superclass or base class). It allows for the creation of a new class that is based on an existing class, enabling code reuse and the extension of functionality.
28 |
29 | 4. **Polymorphism**:
30 | - Polymorphism allows objects to be treated as instances of their parent class rather than their actual class. The most common use of polymorphism is when a parent class reference is used to refer to a child class object. It enables the same operation to behave differently on different classes.
31 |
32 | 5. **Abstraction**:
33 | - Abstraction is the concept of hiding the complex implementation details and showing only the essential features of an object. It helps in reducing programming complexity and effort.
34 |
35 | These concepts together make OOP a powerful and flexible programming paradigm, promoting code reusability, scalability, and maintainability.
36 |
--------------------------------------------------------------------------------
/src/Main.java:
--------------------------------------------------------------------------------
1 | import Object.personalData;
2 | import abstracts.samsung;
3 | import encapsulation.person;
4 | import interfaces.animal;
5 | import interfaces.data;
6 | import interfaces.dog;
7 | import methordOverriding.daughter;
8 | import org.w3c.dom.ls.LSOutput;
9 | import superKeyword.son;
10 |
11 | class test{
12 | void testing(){
13 | System.out.println("class");
14 | }
15 | }
16 |
17 | class Bike{
18 | void run(){
19 | System.out.println("bike is running");
20 | }
21 | }
22 |
23 | class yamaha extends Bike{
24 | @Override
25 | void run(){
26 | System.out.println("yamaha bike is running");
27 | }
28 |
29 | void demo(){
30 | System.out.println("bike bike");
31 | }
32 | }
33 |
34 |
35 | // multi level inherit example (using extends)
36 |
37 | class Animal{
38 | void eat(){
39 | System.out.println("eating");
40 | }
41 | }
42 |
43 | class Dog extends Animal{
44 | @Override
45 | void eat(){
46 | System.out.println("dog is eating");
47 | }
48 | }
49 |
50 | class BabyDog extends Dog{
51 | @Override
52 | void eat(){
53 | System.out.println("Baby Dog is eating");
54 | }
55 | }
56 |
57 | class ICT {
58 | public void eatIct(String name){
59 | int age = 12;
60 | System.out.println("Age is " + age);
61 | System.out.println(name);
62 | }
63 |
64 | }
65 |
66 | public class Main {
67 |
68 | public static void main(String[] args) {
69 | //System.out.println("Hello world!");
70 |
71 | personalData p1 = new personalData();
72 | // p1.name();
73 |
74 | test t1 = new test();
75 | t1.testing();
76 | // Encapsulation part
77 | // object create to encapsulation class
78 |
79 | person p = new person();
80 |
81 | // set the value to id
82 | p.setId(20);
83 | // set the value to name
84 | p.setName("Sanchitha");
85 | p.setDepartment("ICT");
86 |
87 | // print the id value using getters
88 | System.out.println("id is "+p.getId());
89 | // print the name value using getters
90 | System.out.println("name is "+p.getName());
91 | // print the value of private variable "department"
92 | System.out.println(p.getDepartment());
93 |
94 | // used super keyword
95 |
96 | son s = new son();
97 | son s2 = new son(2);
98 |
99 |
100 | // method overriding
101 |
102 | daughter d = new daughter();
103 |
104 | d.phone(); // override method
105 | d.id(); // non-override method
106 |
107 |
108 | // abstract
109 | // we can not create object using abstract class
110 |
111 | samsung ph = new samsung();
112 | ph.call();
113 | ph.sleep();
114 | ph.vibrate();
115 | ph.talk();
116 |
117 | // final keyword
118 |
119 | finalKeyword k = new finalKeyword();
120 | k.laps = 15;
121 |
122 | System.out.println(k.laps);
123 | System.out.println(k.race); // final instant variable
124 |
125 | k.school(); // final method
126 |
127 | // interfaces
128 |
129 | dog ui = new dog();
130 | ui.eat();
131 | ui.sleep();
132 | ui.getup();
133 | ui.newmethod(); // default method in interface
134 | // we can call to static method using interface name and static method name
135 | animal.newmethod1(); // static method can access via interface
136 |
137 | ui.data();
138 | ui.data1();
139 | data.data2();
140 | // --> run time polymorphism
141 |
142 | // we can say dynamic method dispatch to run time polymorphism
143 | // we use overloading and overriding concept to do polymorphism concept
144 |
145 | Bike z = new yamaha();
146 | z.run();
147 | yamaha hh = new yamaha();
148 | hh.demo();
149 |
150 | // multi level inherit
151 | Animal a1,a2,a3;
152 | a1 = new Animal();
153 | a2 = new Dog();
154 | a3 = new BabyDog();
155 |
156 | a1.eat();
157 | a2.eat();
158 | a3.eat();
159 |
160 | ICT i1 = new ICT();
161 | i1.eatIct("sanchitha");
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 | }
170 | }
--------------------------------------------------------------------------------
/.idea/uiDesigner.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | -
6 |
7 |
8 | -
9 |
10 |
11 | -
12 |
13 |
14 | -
15 |
16 |
17 | -
18 |
19 |
20 |
21 |
22 |
23 | -
24 |
25 |
26 |
27 |
28 |
29 | -
30 |
31 |
32 |
33 |
34 |
35 | -
36 |
37 |
38 |
39 |
40 |
41 | -
42 |
43 |
44 |
45 |
46 | -
47 |
48 |
49 |
50 |
51 | -
52 |
53 |
54 |
55 |
56 | -
57 |
58 |
59 |
60 |
61 | -
62 |
63 |
64 |
65 |
66 | -
67 |
68 |
69 |
70 |
71 | -
72 |
73 |
74 | -
75 |
76 |
77 |
78 |
79 | -
80 |
81 |
82 |
83 |
84 | -
85 |
86 |
87 |
88 |
89 | -
90 |
91 |
92 |
93 |
94 | -
95 |
96 |
97 |
98 |
99 | -
100 |
101 |
102 | -
103 |
104 |
105 | -
106 |
107 |
108 | -
109 |
110 |
111 | -
112 |
113 |
114 |
115 |
116 | -
117 |
118 |
119 | -
120 |
121 |
122 |
123 |
124 |
--------------------------------------------------------------------------------