The Artima Developer Community
Sponsored Link

Java Answers Forum
test

1 reply on 1 page. Most recent reply: Jul 7, 2005 2:57 AM by Antonio

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Senthoorkumaran Punniamoorthy

Posts: 335
Nickname: senthoor
Registered: Mar, 2002

test Posted: Mar 1, 2005 3:47 AM
Reply to this message Reply
Advertisement
package com.senthoor.test;
 
class Human {
  public String message = "NONE";
  public Human() {
    
    System.out.println("1");
    message = "ONE";
  }
 
  public Human(String x) {
    System.out.println("2");
    message = "TWO";
  }
}
 
public class Student
    extends Human {
  public Student() {
    System.out.println("3");
    message = "THREE";
  }
 
  public Student(String x) {
    System.out.println("4");
    message = "FOUR";
  }
 
  public static void main(String[] args) {
    Human x = new Student("test");
    System.out.println(x.message);
  }
}


Antonio

Posts: 33
Nickname: arhak
Registered: Jul, 2005

Re: test Posted: Jul 7, 2005 2:57 AM
Reply to this message Reply
What is the question?
Do you want the output?
Here it is:
1
4
FOUR

the first line it the parent's constructor invoked implicitly
the second line is the heir's constructor
the third line is "FOUR" because the heir's constructor overrides what the parent's constructor did

Flat View: This topic has 1 reply on 1 page
Topic: operator overlaoding in java Previous Topic   Next Topic Topic: Reflect Error (bug?)

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use