From b7ff45a174519b82e04b259f6e129be568916b96 Mon Sep 17 00:00:00 2001 From: lonecoder-gittykitty <108501732+lonecoder-gittykitty@users.noreply.github.com> Date: Tue, 8 Nov 2022 06:58:26 +0530 Subject: [PATCH 1/4] oops java oops part added whatever i have done hope it helps --- Main.java | 0 abstract1.java | 48 ++++++++++++++++++++++++++++++++ encapsulation.java | 13 +++++++++ hierarichal.java | 36 ++++++++++++++++++++++++ inheritance.java | 23 ++++++++++++++++ interfaces.java | 34 +++++++++++++++++++++++ lec1.java | 55 +++++++++++++++++++++++++++++++++++++ method_overloading.java | 19 +++++++++++++ method_overriding.java | 17 ++++++++++++ multiLevel_Inheritance.java | 27 ++++++++++++++++++ packages.java | 9 ++++++ static_keyword.java | 32 +++++++++++++++++++++ super_keyword.java | 19 +++++++++++++ typesOfconstructors.java | 54 ++++++++++++++++++++++++++++++++++++ 14 files changed, 386 insertions(+) create mode 100644 Main.java create mode 100644 abstract1.java create mode 100644 encapsulation.java create mode 100644 hierarichal.java create mode 100644 inheritance.java create mode 100644 interfaces.java create mode 100644 lec1.java create mode 100644 method_overloading.java create mode 100644 method_overriding.java create mode 100644 multiLevel_Inheritance.java create mode 100644 packages.java create mode 100644 static_keyword.java create mode 100644 super_keyword.java create mode 100644 typesOfconstructors.java diff --git a/Main.java b/Main.java new file mode 100644 index 0000000..e69de29 diff --git a/abstract1.java b/abstract1.java new file mode 100644 index 0000000..12be7c6 --- /dev/null +++ b/abstract1.java @@ -0,0 +1,48 @@ +public class abstract1{ + public static void main(String args[]){ +// Horse h=new Horse(); +// h.eat(); +// h.walk(); +// System.out.println(h.color); +// Chicken c=new Chicken(); +// c.eat(); +// c.walk(); + Mustang myHorse=new Mustang(); + // Animal4 a =new Animal4(); can't create object of abstract class + } + +} +abstract class Animal4{ + Animal4(){ + System.out.println("animal constructor called"); + } + String color; +// Animal4(){ +// color="brown"; +// } + void eat(){ + System.out.println("animal eats"); + } + abstract void walk(); +} +class Horse extends Animal4{ + Horse(){ + System.out.println("horse constructor called"); + } + void changeColor(){ + color="dark brown"; + } + void walk(){ + System.out.println("walks on 4 legs"); + } +} +class Mustang extends Horse{ + Mustang(){ + System.out.println("Mustang constructor called"); + } +} +class Chicken extends Animal4{ + void walk(){ + System.out.println("walks on 2 legs"); + } +} \ No newline at end of file diff --git a/encapsulation.java b/encapsulation.java new file mode 100644 index 0000000..d2acfce --- /dev/null +++ b/encapsulation.java @@ -0,0 +1,13 @@ +public class encapsulation{ + public static void main(String args[]){ + //System.out.println("encapsulation"); + Student1 s1=new Student1(); + } +} +class Student1{ + String name; + int roll; + Student1(){ + System.out.println("constructor is called..."); + } +} \ No newline at end of file diff --git a/hierarichal.java b/hierarichal.java new file mode 100644 index 0000000..02b1314 --- /dev/null +++ b/hierarichal.java @@ -0,0 +1,36 @@ +public class hierarichal { + public static void main(String args[]){ + Bird dobby1=new Bird(); + dobby1.eat(); +// dobby1.legs=4; +// System.out.println(dobby1.legs); + dobby1.breathe(); + dobby1.fly(); + + } +} +//base class +class Animal2{ + String color; + void eat(){ + System.out.println("eats"); + } + void breathe(){ + System.out.println("breathes"); + } +} +//derived class / subclass +class Mammal1 extends Animal2 { + void walk(){ + System.out.println("walks"); + } +}class Fish1 extends Animal2 { + void swim(){ + System.out.println("swim"); + } +}class Bird extends Animal2 { + void fly(){ + System.out.println("fly"); + } +} + diff --git a/inheritance.java b/inheritance.java new file mode 100644 index 0000000..6486ea8 --- /dev/null +++ b/inheritance.java @@ -0,0 +1,23 @@ +public class inheritance { + public static void main(String args[]){ + Fish shark=new Fish(); + shark.eat(); + } +} +//base class +class Animal{ + String color; + void eat(){ + System.out.println("eats"); + } + void breathe(){ + System.out.println("breathes"); + } +} +//derived class / subclass +class Fish extends Animal{ + int fins; + void swim(){ + System.out.println("swims in water"); + } +} diff --git a/interfaces.java b/interfaces.java new file mode 100644 index 0000000..ed392c3 --- /dev/null +++ b/interfaces.java @@ -0,0 +1,34 @@ +public class interfaces{ + public static void main(String args[]){ + Queen q=new Queen(); + q.moves(); + } +} +interface ChessPlayer{ + void moves(); +} +interface Herbivore{ + +} +interface Carnivore{ + +} +class Bear implements Herbivore,Carnivore{ + +} +class Queen implements ChessPlayer{ + + public void moves() { + System.out.println("up down left right diagonal (in all 4dirns)"); + } +} +class Rook implements ChessPlayer{ + public void moves(){ + System.out.println("up down left right"); + } +} +class King implements ChessPlayer{ + public void moves(){ + System.out.println("up down left right diagonal-(by 1 step)"); + } +} diff --git a/lec1.java b/lec1.java new file mode 100644 index 0000000..a6708a3 --- /dev/null +++ b/lec1.java @@ -0,0 +1,55 @@ +public class lec1 { + public static void main(String args[]) { +// Pen p1 = new Pen(); //created a pen object called p1 +// p1.setColor("Blue"); +// System.out.println(p1.color); +// p1.setTip(5); +// System.out.println(p1.tip); +// p1.color="Yellow"; +// System.out.println(p1.color); +// BankAccount myAcc=new BankAccount(); +// myAcc.username="shraddhaKhapra"; +// myAcc.setPassword("abcdefghi"); + Pen p1 = new Pen(); //created a pen object called p1 + p1.setColor(("Blue")); + System.out.println(p1.getColor()); + p1.setTip(5); + System.out.println(p1.getTip()); + p1.setColor("Yellow"); + System.out.println(p1.getColor()); + } +} +//class BankAccount{ +// public String username; +// private String password; +// +// public void setPassword(String pwd) { +// password = pwd; +// } +//} +class Pen{ + private String color; + private int tip; + String getColor(){ + return this.color; + } + int getTip(){ + return this.tip; + } + + void setColor(String newColor){ + color=newColor; + } + void setTip(int newTip){ + tip=newTip; + } +} +class Student{ + String name; + int age; + float percentage;//cgpa + + void calcPercentage(int phy,int chem,int math){ + percentage=(phy+chem+math)/3; + } +} diff --git a/method_overloading.java b/method_overloading.java new file mode 100644 index 0000000..95788c0 --- /dev/null +++ b/method_overloading.java @@ -0,0 +1,19 @@ +class method_overloading{ + public static void main(String args[]){ + Calculator calc=new Calculator(); + System.out.println(calc.sum(1,2)); + System.out.println(calc.sum((float)1.5,(float)2.5)); + System.out.println(calc.sum(1,2,3)); + } +} +class Calculator{ + int sum(int a,int b){ + return a+b; + } + float sum(float a,float b){ + return a+b; + } + int sum(int a ,int b ,int c){ + return a+b+c; + } +} \ No newline at end of file diff --git a/method_overriding.java b/method_overriding.java new file mode 100644 index 0000000..724a9d2 --- /dev/null +++ b/method_overriding.java @@ -0,0 +1,17 @@ +class method_overriding{ + public static void main(String args[]){ + Deer d=new Deer(); + d.eat(); + } + +} +class Animal3 { + void eat(){ + System.out.println("eats anything"); + } +} +class Deer extends Animal{ + void eat(){ + System.out.println("eats grass"); + } +} \ No newline at end of file diff --git a/multiLevel_Inheritance.java b/multiLevel_Inheritance.java new file mode 100644 index 0000000..7845a94 --- /dev/null +++ b/multiLevel_Inheritance.java @@ -0,0 +1,27 @@ +public class multiLevel_Inheritance { + public static void main(String args[]){ + Dog dobby=new Dog(); + dobby.eat(); + dobby.legs=4; + System.out.println(dobby.legs); + + } +} +//base class +class Animal1{ + String color; + void eat(){ + System.out.println("eats"); + } + void breathe(){ + System.out.println("breathes"); + } +} +//derived class / subclass +class Mammal extends Animal1 { + int legs; +} +class Dog extends Mammal{ + String breed; + } + diff --git a/packages.java b/packages.java new file mode 100644 index 0000000..453c931 --- /dev/null +++ b/packages.java @@ -0,0 +1,9 @@ +package myPackage; +import java.util.*; +public class packages{ + public static void main(String args[]){ + Scanner sc=new Scanner(System.in); + int a=sc.nextInt(); + System.out.println(a); + } +} \ No newline at end of file diff --git a/static_keyword.java b/static_keyword.java new file mode 100644 index 0000000..176a82f --- /dev/null +++ b/static_keyword.java @@ -0,0 +1,32 @@ +public class static_keyword { + + public static void main(String args[]) { + Student3 s1=new Student3(); + s1.schoolName="MVN"; + + Student3 s2=new Student3(); + System.out.println(s2.schoolName); + + Student3 s3=new Student3(); + s3.schoolName="ABC"; + System.out.println(s2.schoolName); + + + + } +} +class Student3{ + static int returnPercentage(int math,int phy,int chem){ + return (math+phy+chem)/3; + } + String name; + int roll; + + static String schoolName; + void setName(String name){ + this.name=name; + } + String getName(){ + return this.name; + } +} \ No newline at end of file diff --git a/super_keyword.java b/super_keyword.java new file mode 100644 index 0000000..731f86d --- /dev/null +++ b/super_keyword.java @@ -0,0 +1,19 @@ +public class super_keyword{ + public static void main(String args[]){ + Horse1 h=new Horse1(); + System.out.println(h.color); + } + +} +class Animal5{ + String color; + Animal5(){ + System.out.println("animal constructor is called"); + } +} +class Horse1 extends Animal5{ + Horse1(){ + super.color="brown"; + System.out.println("horse constructor is called"); + } +} \ No newline at end of file diff --git a/typesOfconstructors.java b/typesOfconstructors.java new file mode 100644 index 0000000..c0808dc --- /dev/null +++ b/typesOfconstructors.java @@ -0,0 +1,54 @@ +public class typesOfconstructors { + //copy constructor + public static void main(String args[]){ + Student2 s1=new Student2(); + s1.name=("shraddha"); + s1.roll=456; + s1.password="abcd"; + s1.marks[0]=100; + s1.marks[1]=90; + s1.marks[2]=80; + //Student2 s4=new Student2("aman",567); + Student2 s2=new Student2(s1); + s2.password="xyz"; + for(int i=0;i<3;i++){ + System.out.println(s2.marks[i]); + } + } +} +class Student2{ + String name; + int roll; + String password; + int marks[]; +// class Address{ +// String city; +// } + + //shallow copy constructor +// Student2(Student2 s1){ +// marks=new int[3]; +// this.name=s1.name; +// this.roll=s1.roll; +// this.marks=s1.marks; +// } + //deep copy constructor + Student2(Student2 s1){ + marks=new int[3]; + this.name=s1.name; + this.roll=s1.roll; + for(int i=0;i Date: Tue, 8 Nov 2022 06:59:24 +0530 Subject: [PATCH 2/4] Delete Main.java --- Main.java | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 Main.java diff --git a/Main.java b/Main.java deleted file mode 100644 index e69de29..0000000 From 580d6346ef72d51ddb4fc914952a63e67645371c Mon Sep 17 00:00:00 2001 From: lonecoder-gittykitty <108501732+lonecoder-gittykitty@users.noreply.github.com> Date: Tue, 8 Nov 2022 06:59:57 +0530 Subject: [PATCH 3/4] Create oops java --- oops java | 1 + 1 file changed, 1 insertion(+) create mode 100644 oops java diff --git a/oops java b/oops java new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/oops java @@ -0,0 +1 @@ + From 01d59ad97a88c5973b12eb159f3fdc5b3aff10cb Mon Sep 17 00:00:00 2001 From: lonecoder-gittykitty <108501732+lonecoder-gittykitty@users.noreply.github.com> Date: Tue, 8 Nov 2022 07:00:18 +0530 Subject: [PATCH 4/4] Delete oops java --- oops java | 1 - 1 file changed, 1 deletion(-) delete mode 100644 oops java diff --git a/oops java b/oops java deleted file mode 100644 index 8b13789..0000000 --- a/oops java +++ /dev/null @@ -1 +0,0 @@ -