-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f02f671
commit 3e702ee
Showing
34 changed files
with
337 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
class Base{ | ||
static int i = 0; | ||
static{ | ||
m1(); | ||
System.out.println("base static block"); | ||
} | ||
|
||
public static void main(String[] args){ | ||
m1(); | ||
System.out.println("base main"); | ||
} | ||
|
||
public static void m1(){ | ||
System.out.println(j); | ||
} | ||
|
||
static int j = 20; | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class CheckingDemo{ | ||
public static void main(String[] args){ | ||
Object o = new String("ashok"); | ||
System.out.println("hascode value is " + o.hashCode()); | ||
//System.out.println(o.length()); | ||
|
||
StringBuffer sb = (StringBuffer)o; | ||
System.out.println(sb); | ||
|
||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class ChildClass extends ParentClass{ | ||
ChildClass(){ | ||
System.out.println(this.hashCode()); | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
class ChildInstance extends ParentInstance{ | ||
|
||
int x = 100; | ||
|
||
{ | ||
m2(); | ||
System.out.println("child first instance block"); | ||
} | ||
|
||
ChildInstance(){ | ||
System.out.println("child constructor"); | ||
} | ||
|
||
public static void main(String[] args){ | ||
ChildInstance p = new ChildInstance(); | ||
System.out.println("child main"); | ||
} | ||
|
||
public void m2(){ | ||
System.out.println(y); | ||
} | ||
|
||
{ | ||
System.out.println("child second instance block"); | ||
} | ||
|
||
int y = 200; | ||
|
||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class ConstructorDemo{ | ||
String name; | ||
int rollno; | ||
|
||
ConstructorDemo(String name, int rollno){ | ||
this.name = name; | ||
this.rollno = rollno; | ||
} | ||
|
||
public static void main(String[] args){ | ||
ConstructorDemo d1 = new ConstructorDemo("durga", 1010); | ||
ConstructorDemo d2 = new ConstructorDemo("softie", 2020); | ||
|
||
System.out.println(d1); | ||
System.out.println(d2); | ||
} | ||
|
||
public String toString(){ | ||
return name+" "+rollno; | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
class CountOfObjectsCreated{ | ||
static int count = 0; | ||
|
||
{ | ||
count++; | ||
} | ||
|
||
CountOfObjectsCreated(){ | ||
|
||
} | ||
|
||
CountOfObjectsCreated(int i){ | ||
this("Rani"); | ||
} | ||
|
||
CountOfObjectsCreated(String s){ | ||
this(1000); | ||
} | ||
|
||
CountOfObjectsCreated(char c){ | ||
|
||
} | ||
|
||
public static void main(String[] args){ | ||
CountOfObjectsCreated c1 = new CountOfObjectsCreated(); | ||
CountOfObjectsCreated c2 = new CountOfObjectsCreated(10); | ||
CountOfObjectsCreated c3 = new CountOfObjectsCreated("sudha"); | ||
CountOfObjectsCreated c4 = new CountOfObjectsCreated('s'); | ||
|
||
System.out.println(count); | ||
|
||
|
||
CountOfObjectsCreated c5 = new CountOfObjectsCreated(); | ||
CountOfObjectsCreated c6 = new CountOfObjectsCreated("rani"); | ||
|
||
System.out.println(count); | ||
|
||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
class Derived extends Base{ | ||
static int x = 100; | ||
|
||
static{ | ||
m2(); | ||
System.out.println("derived first static block"); | ||
} | ||
|
||
public static void main(String[] args){ | ||
m2(); | ||
System.out.println("derived main"); | ||
} | ||
|
||
public static void m2(){ | ||
System.out.println(y); | ||
} | ||
|
||
static{ | ||
System.out.println("derived | ||
second static block"); | ||
} | ||
|
||
static int y = 200; | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
public class InitialisationDemo{ | ||
|
||
private static String m1(String msg){ | ||
System.out.println(msg); | ||
return msg; | ||
} | ||
|
||
/* | ||
private static void m1(String msg){ | ||
System.out.println(msg); | ||
} | ||
*/ | ||
|
||
public InitialisationDemo(){ | ||
m = m1("1"); | ||
} | ||
|
||
{ | ||
m = m1("2"); | ||
} | ||
|
||
|
||
String m = m1("3"); | ||
|
||
public static void main(String[] args){ | ||
Object o = new InitialisationDemo(); | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
class InstanceControlFlowDemo{ | ||
|
||
int i = 10; | ||
|
||
{ | ||
m1(); | ||
System.out.println("first instance block"); | ||
} | ||
|
||
InstanceControlFlowDemo(){ | ||
System.out.println("Constructor"); | ||
} | ||
|
||
public static void main(String[] args){ | ||
InstanceControlFlowDemo d = new InstanceControlFlowDemo(); | ||
System.out.println("main"); | ||
} | ||
|
||
public void m1(){ | ||
System.out.println(j); | ||
} | ||
|
||
{ | ||
System.out.println("second instance block"); | ||
} | ||
|
||
int j = 20; | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class MixInitialisationDemo{ | ||
|
||
private static String m1(String msg){ | ||
System.out.println(msg); | ||
return msg; | ||
} | ||
|
||
static String m = m1("1"); | ||
|
||
{ | ||
m = m1("2"); | ||
} | ||
|
||
static{ | ||
m = m1("3"); | ||
} | ||
|
||
public static void main(String[] args){ | ||
Object o = new MixInitialisationDemo(); | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class ParentClass{ | ||
ParentClass(){ | ||
System.out.println(this.hashCode()); | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
class ParentInstance{ | ||
|
||
int i = 10; | ||
|
||
{ | ||
m1(); | ||
System.out.println("parent instance block"); | ||
} | ||
|
||
ParentInstance(){ | ||
System.out.println("parent constructor"); | ||
} | ||
|
||
public static void main(String[] args){ | ||
ParentInstance p = new ParentInstance(); | ||
System.out.println("parent main"); | ||
} | ||
|
||
public void m1(){ | ||
System.out.println(j); | ||
} | ||
|
||
int j = 20; | ||
} | ||
|
||
// 0 | ||
// parent instance block | ||
// parent constructor | ||
// parent main |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
class SingleClientObject{ | ||
public static void main(String[] args){ | ||
SingleTonDemo singleObj = SingleTonDemo.getSingleObject(); | ||
SingleTonDemo singleObj2 = SingleTonDemo.getSingleObject(); | ||
SingleTonDemo singleObj3 = SingleTonDemo.getSingleObject(); | ||
|
||
System.out.println(singleObj.hashCode()); | ||
System.out.println(singleObj2.hashCode()); | ||
System.out.println(singleObj3.hashCode()); | ||
|
||
System.out.println(singleObj == singleObj2); | ||
System.out.println(singleObj == singleObj3); | ||
System.out.println(singleObj2 == singleObj3); | ||
|
||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class SingleTonDemo{ | ||
private static SingleTonDemo d = new SingleTonDemo(); | ||
|
||
private SingleTonDemo(){ | ||
|
||
} | ||
|
||
public static SingleTonDemo getSingleObject(){ | ||
return d; | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
class StaticDemo{ | ||
|
||
/* | ||
static{ | ||
System.out.println(x); | ||
} | ||
static int x = 10; | ||
*/ | ||
|
||
static{ | ||
m1(); | ||
} | ||
|
||
public static void m1(){ | ||
System.out.println(x); | ||
} | ||
|
||
static int x = 10; | ||
|
||
public static void main(String[] args){ | ||
System.out.println("last one to execute"); | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
class Test{ | ||
|
||
public void m1(int i){ | ||
System.out.println("integer"); | ||
} | ||
|
||
public void m1(String i){ | ||
System.out.println("string"); | ||
} | ||
|
||
public void m1(double i){ | ||
System.out.println("double"); | ||
} | ||
|
||
public static void main(String[] args){ | ||
Test t = new Test(); | ||
|
||
t.m1(10); | ||
t.m1("durga"); | ||
t.m1(10.29f); | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class TestClass{ | ||
public static void main(String[] args){ | ||
ChildClass c = new ChildClass(); | ||
System.out.println(c.hashCode()); | ||
} | ||
} |