if (aNumber >= 0) if (aNumber == 0) System.out.println("first string"); else System.out.println("second string"); System.out.println("third string");
class Rectangle { int width; int height; int area() { return width*height; } } public class SomethingIsWrong { public static void main(String[] args) { Rectangle myRect; myRect.width = 40; myRect.height = 50; System.out.println( "myRect's area is " + myRect.area()); } }
class StringTest{ public static void main(String argv[]) { String s1 = "abc"; String s2 = "abc"; char s3[] = {'a','b','c'}; String s4 = new String(s3); System.out.println("s1:" + s1 + " s2:" + s2 + " s3:" + s3 + " s4:" + s4); if (s1 == s2) System.out.println("s1 == s2 true"); if (s1 == s4) System.out.println("s1 == s4 true"); if (s2 == s4) System.out.println("s2 == s4 true"); } }
class A { String str="A"; A() { System.out.println("A() " + str); System.out.println("A() " + this.str); } A(String str) { System.out.println(str); System.out.println(this.str); } } class B extends A { String str="B"; B() { System.out.println("B() " + str); System.out.println("B() " + this.str); System.out.println("B() " + super.str); } B(String str) { System.out.println(str); System.out.println(this.str); System.out.println(super.str); } } class C extends B { C() {System.out.println("C() C");} C(String str) { System.out.println(str); System.out.println(this.str); System.out.println(super.str); } } public class Construct2 { public static void main(String str[]) { C m = new C(); System.out.println("--"); C m2 = new C("C"); } }
class SuperShow { public String str = "SuperStr"; public void show() { System.out.println("Super.show: " + str); } } class ExtendShow extends SuperShow { public String str = "ExtendStr"; public void show() { System.out.println("Extend.show: " + str); } public static void main(String[] args) { ExtendShow ext = new ExtendShow(); SuperShow sup = ext; sup.show(); ext.show(); System.out.println("sup.show: " + sup.str); System.out.println("ext.show: " + ext.str); } }