Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The code for an ITD introduction is no different that the code that you would add to a class directly. So without member initialization code in your introduced constructor, members will , of course, remain uninitialized. So you need to change you code in Q1 as follows.</p> <pre><code>public Child.new(String name, int age) { this.name = name; this.age = age; System.out.println("Child Name:" + this.name); } </code></pre> <p>As for Q2, it works fine for me.</p> <pre><code>class Parent { public void init() { System.out.println("P.init"); } } class Child extends Parent { } aspect Intro { public void Child.init(){ super.init(); System.out.println("C.init"); } } public class Main { public static void main(String[] args) { Child c = new Child(); c.init(); } } </code></pre> <p>prints:</p> <pre><code>P.init C.init </code></pre> <p>Changing the introduced method to something other than <code>init</code> works too (to match your code).</p> <p>Regarding your comment: I fail to see what difference you have made in Q1. Sorry, I don't get it.</p> <p>As for Q2 part of your comment, constructor arrangement works for me:</p> <pre><code>class Parent { protected String name; public Parent(String name) { this.name = name; } } class Child extends Parent { int age; public Child(String name) { super(name); } } aspect Intro { public Child.new(String name, int age){ super(name); this.age = age; System.out.println("this.name: " + this.name + " this.age: " + this.age); } } </code></pre> <p>prints <code>this.name: myname this.age: 2</code></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload