From 849d411e86ea2c30edeadce665cd7cb84c384b1d Mon Sep 17 00:00:00 2001 From: chanuka96 <65078466+chanuka96@users.noreply.github.com> Date: Thu, 21 Oct 2021 17:40:09 +0530 Subject: [PATCH 1/3] Update Sample.java --- .../1. Inheritance/1. Introduction/Sample.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/1. Object Oriented Programming/1. Inheritance/1. Introduction/Sample.java b/1. Object Oriented Programming/1. Inheritance/1. Introduction/Sample.java index f091773..eff8fcf 100644 --- a/1. Object Oriented Programming/1. Inheritance/1. Introduction/Sample.java +++ b/1. Object Oriented Programming/1. Inheritance/1. Introduction/Sample.java @@ -1,5 +1,8 @@ public class Sample{ public static void main(String[] args) { + Dog dog = new Dog(); + dog.foo(); + dog.bar(); } } @@ -14,4 +17,4 @@ class Dog extends Animal{ void bar(){ System.out.println("I am a Dog"); } -} \ No newline at end of file +} From 8748119f685f302ab738e215a18bfb94c7f6a2eb Mon Sep 17 00:00:00 2001 From: chanuka96 <65078466+chanuka96@users.noreply.github.com> Date: Sun, 24 Oct 2021 05:37:18 +0530 Subject: [PATCH 2/3] Update encapsulation.java --- .../1. Introduction/encapsulation.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/1. Object Oriented Programming/1. Inheritance/1. Introduction/encapsulation.java b/1. Object Oriented Programming/1. Inheritance/1. Introduction/encapsulation.java index 547bd7b..53c231d 100644 --- a/1. Object Oriented Programming/1. Inheritance/1. Introduction/encapsulation.java +++ b/1. Object Oriented Programming/1. Inheritance/1. Introduction/encapsulation.java @@ -1,3 +1,30 @@ + + class Test { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + + + + Dog dog = new Dog(); + + dog.setBreed("German Sheperd"); + dog.setAge(5); + dog.setColor("Brown"); + dog.setSize(2); + + + System.out.println(dog.getBreed()); + System.out.println(dog.getAge()+" years old "); + System.out.println(dog.getColor()+" color"); + System.out.println(dog.getSize() +" feet height"); + } + +} + + public class Dog { //using private access modifiers @@ -32,6 +59,8 @@ public int getAge() { //getter to get age public void setAge(int age) { //setter to set age Age = age; } + + public int getSize() { //getter to get size return Size; @@ -40,3 +69,4 @@ public int getSize() { //getter to get size public void setSize(int size) { //setter to set size Size = size; } +} From 4298e5d55238c71d01a421c3d5817ace57899deb Mon Sep 17 00:00:00 2001 From: chanuka96 <65078466+chanuka96@users.noreply.github.com> Date: Sun, 24 Oct 2021 05:54:20 +0530 Subject: [PATCH 3/3] Update sample.java --- .../2.abstraction/introduction/sample.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/1. Object Oriented Programming/2.abstraction/introduction/sample.java b/1. Object Oriented Programming/2.abstraction/introduction/sample.java index 3217eec..d0272f4 100644 --- a/1. Object Oriented Programming/2.abstraction/introduction/sample.java +++ b/1. Object Oriented Programming/2.abstraction/introduction/sample.java @@ -2,7 +2,7 @@ public class sample { public static void main(String[] args) { Dog dog=new Dog();//create a dog object dog.animalSound(); - + dog.animalFeature(); } } @@ -10,6 +10,11 @@ public static void main(String[] args) { abstract class Animal{ // Abstract method (does not have a body) public abstract void animalSound(); + + public void animalFeature(){ + System.out.println("Has 4 legs/limbs"); + + } } // Subclass (inherit from Animal)