Commit edd01816 authored by updjx's avatar updjx

trying to fix disscusion comments

parent c1c61750
...@@ -2,28 +2,26 @@ class AttributeKill { ...@@ -2,28 +2,26 @@ class AttributeKill {
public A objectA; public A objectA;
public static void main(String[] args) { public static void main(String[] args) {
/* create and construct object A*/
A objectA = new A(); A objectA = new A();
objectA.init(); objectA.init();
/* set object to null*/
objectA = null; objectA = null;
/* calling uninitiated attribute of null object*/
int a = objectA.atr; int a = objectA.atr;
} }
} }
class A { class A {
public int atr; public int atr;
/* pseudo constructor */ /* pseudo constructor */
public void init () { public void init() {
atr = 2; atr = 2;
} }
} }
\ No newline at end of file
...@@ -4,13 +4,16 @@ ...@@ -4,13 +4,16 @@
*/ */
class NoParameterDeclaration { class NoParameterDeclaration {
public int a;
public static void main(String[] args) { public static void main(String[] args) {
NoParameterDeclaration testObj = new NoParameterDeclaration();
/*there is no parameter given here*/ /*there is no parameter given here*/
testObj.test(); testObj.test();
} }
public void test (int i) { public void test(int i) {
int a = i; int a = i;
} }
......
class OverwriteAttributeWithUndeclaredVariable { class OverwriteAttributeWithUndeclaredVariable {
public static void main(String[] args) {}
public String a; public String a;
public void test () { public static void main(String[] args) {
/*should break here because of undeclared unknown variable*/
int a = i; OverwriteAttributeWithUndeclaredVariable obj = new OverwriteAttributeWithUndeclaredVariable();
obj.test();
} }
public void test() {
/*should break here because of undeclared unknown variable*/
a = i;
}
} }
class String {} class String {
}
...@@ -3,7 +3,8 @@ ...@@ -3,7 +3,8 @@
*/ */
class RightVariable { class RightVariable {
public static void main(String[] args) {} public static void main(String[] args) {
}
public int Test; public int Test;
...@@ -27,20 +28,19 @@ class RightVariable { ...@@ -27,20 +28,19 @@ class RightVariable {
/*Overwrite test attribute with RightVariable class Attribute*/ /*Overwrite test attribute with RightVariable class Attribute*/
test.Test = Test; test.Test = Test;
/*call local method with test*/ /*call class RightVariable method Test, with the test object declared in the current method*/
Test(test); Test(test);
/*Overwrite class Test with with local method Test, with itself given as an obj ref..*/ /*Overwrite class Test with with local method Test, with itself given as an obj ref..*/
test = Test(test); test = Test(test);
} }
} }
class Test { class Test {
public int Test; public int Test;
public void Test() {} public void Test() {
}
} }
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment