diff --git a/constructor/ConstructorClass.java b/constructor/ConstructorClass.java new file mode 100644 index 0000000..2f6b4fe --- /dev/null +++ b/constructor/ConstructorClass.java @@ -0,0 +1,63 @@ +package constructor; + +public class ConstructorClass { + + public static void main(String[] args) { + One one = new One(); + Two two = new Two(); + Three three = new Three(19, "dev"); + System.out.println(one.a); + System.out.println(two.a); + System.out.println(three.a+" "+three.name); + one.display(); + two.display(); + three.display(); + } + +} + +class One{ + + //default constructor + + int a; + void display() { + System.out.println(a); + } + +} + +class Two{ + + //no argument constructor + public Two(){ + a = 9; + } + + public Two(int a) { + a = this.a; + System.out.println("a"); + } + int a; + void display() { + System.out.println(a); + } + +} + + +class Three{ + int a; + String name; + + //parameterized constructor + public Three(int a, String name){ + this.name = name; + this.a = a; + } + void display() { + System.out.println(a); + System.out.println(name); + } + +} diff --git a/exceptionsHandling/PracticeExceptionHandling.java b/exceptionsHandling/PracticeExceptionHandling.java new file mode 100644 index 0000000..2785b52 --- /dev/null +++ b/exceptionsHandling/PracticeExceptionHandling.java @@ -0,0 +1,21 @@ +package exceptionsHandling; + +public class PracticeExceptionHandling { + + public static void main(String[] args) { + + try { + int a = 7; + int b = 0; + int c = a/b; + System.out.println(c); + }catch(ArithmeticException e) { + System.out.println(e.getMessage()+" the value of denomenator can't be 0"); + } + finally { + System.out.println("bye bye"); + } + } + + } + diff --git a/staticKeyword/StaticClass.java b/staticKeyword/StaticClass.java new file mode 100644 index 0000000..48dd420 --- /dev/null +++ b/staticKeyword/StaticClass.java @@ -0,0 +1,10 @@ +package staticKeyword; + +public class StaticClass { + + static class Hi{ + void display() { + System.out.println("Hi"); + } + } +} diff --git a/staticKeyword/StaticKeyword.java b/staticKeyword/StaticKeyword.java new file mode 100644 index 0000000..dbff756 --- /dev/null +++ b/staticKeyword/StaticKeyword.java @@ -0,0 +1,21 @@ +package staticKeyword; + + +public class StaticKeyword { +// static int a = 9; +// a = 8; + static { + + System.out.println("inside static block"); + + } + public static void main(String[] args) { + System.out.println("Hello, My name is dev kumar"); + staticKeyword.StaticClass.Hi h = new staticKeyword.StaticClass.Hi(); + h.display(); + + } +} + + +