[Help] Using a class at the other class

hi guys, i'm still new to java. So that i tried to learn by myself.
i got 2 class: 'Person.java' and 'Ex1.java'
basically, Person just a class for making an object of Person. and the main function is made at Ex1.java.
my problem is: i made 2 Person objects (p1 and p2). then i tried to initialise them in 2 ways (using default constructor and user-defined constructor). Why when i print 'em (p1.print() and p2.print()), it printed p1 attributes only. I tried many ways to do this, but can't find the way out. pls help me...
* Person.java *
public class Person {
     // attributes
     private static String name;
     private static int age;
     // constructor
     public Person() {
          name = "";
          age = -1;
     public Person(String n, int a) {
          name = n;
          age = a;
     // mutator
     public static void setName( String n ) { name = n; }
     public static void setAge( int a) { age = a; }
     // other methods
     public static void print() {
          System.out.println( name + " (" + age + " years old)" );
* Ex1.java *
public class Ex1{
     private static Person p1;
     private static Person p2;
     public static void main(String args[]) {
          p1 = new Person();
          p2 = new Person("Jessica", 25);
          p1.setName("Antonio");
          p1.setAge(20);
          p1.print();
          p2.print();
}

Change
public class Person {
     // attributes
     private static String name;
     private static int age;
to
public class Person {
     // attributes
     private String name;
     private int age;
You're using incorrectly static for object attributes:)

Similar Messages

  • Can I use the inner class of one containing class by the other class

    Can I use the inner class of one containing class by the other class in the same package as the containing class
    eg I have a class BST which has inner class Enumerator. Can I use the inner class from the other class in the same pacckage as BST?

    Inner classes do not share the namespace of the package of the containing class. Also they are never visible to other classes in the same package.Believe what you want, then, if you're going to make up your own rules about how Java works. For people interested in how Java actually works, here is an example that shows why that assertion is false:
    package com.yawmark.jdc;
    public class Outer {
         public class Inner {
    }And...
    package com.yawmark.demo;
    import com.yawmark.jdc.*;
    public class Demo {
         public static void main(String[] args) {
              assert new Outer().new Inner() != null;
    }~

  • How to convert the class in the one package to same class in the other pack

    How to convert the class in the one package to same class in the other package
    example:
    BeanDTO.java
    package cho3.hello.bean;
    public class BeanDTO {
    private String name;
    private int age;
    * @return
    public int getAge() {
         return age;
    * @return
    public String getName() {
         return name;
    * @param i
    public void setAge(int i) {
         age = i;
    * @param string
    public void setName(String string) {
         name = string;
    BeanDTO.java in other package
    package ch03.hello;
    public class BeanDTO {
    private String name;
    private int age;
    * @return
    public int getAge() {
         return age;
    * @return
    public String getName() {
         return name;
    * @param i
    public void setAge(int i) {
         age = i;
    * @param string
    public void setName(String string) {
         name = string;
    My converter lass lokks like
    public class BeanUtilTest {
         public static void main(String[] args) {
              try
                   ch03.hello.BeanDTO bean=new ch03.hello.BeanDTO();
              bean.setAge(10);
              bean.setName("mahesh");
              cho3.hello.bean.BeanDTO beanDto=new cho3.hello.bean.BeanDTO();
              ClassConverter classconv=new ClassConverter();
              //classconv.
              System.out.println("hi "+beanDto.getClass().toString());
              System.out.println("hi helli "+bean.toString()+" "+bean.getAge()+" "+bean.getName()+" "+bean.getClass());
              Object b=classconv.convert(beanDto.getClass(),(Object)bean);
              System.out.println(b.toString());
              beanDto= (cho3.hello.bean.BeanDTO)b;
              System.out.println(" "+beanDto.getAge()+" "+beanDto.getName() );
              }catch(Exception e)
                   e.printStackTrace();
    But its giving class cast exception. Please help on this..

    Do you mean "two different layers" as in separate JVMs or "two different layers" as in functional areas running within the same JVM.
    In either case, if the first class is actually semantically and functionally the same as the second (and they are always intended to be the same) then import and and use the first class in place of the second. That's beyond any question of how to get the data of the first into the second if and when you need to.
    Once you make the breakthrough and use one class instead of two I'd guess that almost solves your problem. But if you want to describe your architecture a little that would help others pin down want you're trying to do.

  • How can a class listen to other class's aoutput

    I have 2 classes which are both unrelated. but i want one class to listen to the output emitted by the other class. eg, class A continuosly prints messages and these messages, i want to be there in class B ...
    Any suggestions?

    I have 2 classes which are both unrelated. but i want
    one class to listen to the output emitted by the
    other class. eg, class A continuosly prints messages
    and these messages, i want to be there in class B
    Any suggestions?Classes do not listen to other classes but objects created from the classes can listen to other objects.
    eg.
    class A {
        public void sendMessage(B b) {
           b.setMessage(String aMessageFormA);
        public static void main(String[] args) {
            A a = new A();
            B b = new B();
            a.sendMessage(b);
            b.printMessageFromA();
    }

  • I have a problem with my iPhone 5 stopped working the sleep / power and simultaneously refused to obey the HOME button. I can not use either one or the other. I can not enable or disable the device, display lights up when you plug the charger. same displa

    I have a problem with my iPhone 5 stopped working the sleep / power and simultaneously refused to obey the HOME button. I can not use either one or the other. I can not enable or disable the device, display lights up when you plug the charger. same display works fine as it is surprising. or maybe someone knows what is the reason for this? is there any way to solve this problem?

    More than likely its a hardware issue, I have never encountered such a problem and best bet is to just go get it replaced. If you have insurance on your device apple will replace it as long as there was no water damage, if you dont have insurance they will charge $200 more or less. Hope you get it fixed

  • Help with using 'extend' while creating a class between two other classes

    I have an assignment, basically to take a Date class and make it so it can output the date to a String, so if it was 4/2006, it would do April 2006.
    Now my question is, where and when do I put super? I can post what I have and I can post the two programs that are given to us.
    http://faculty.stcc.edu/silvestri/csci401/CourseArea/supplements/Date.java
    is the Date class
    http://faculty.stcc.edu/silvestri/csci401/CourseArea/solutions/ExtDateDriver.java
    Is the class test used to run we have to create. Thanks for your time.

    Awesome, should have just read a couple of threads to see that all of you guys are ass holes, by the way dip shit, instead of being a lazy fuck you are, why don't you fucking try and read the question I'm asking, the homework question, and try to answer my fucking question,
    I have already started the class for it, and I don't need your fucking retarded statments in MY thread, so just either help, or shut you little 4 year old mouth up.

  • Please Help!!! Problems access other classes methods

    I am having a problem accessing another classes methods varibles. I have tried a number of ways but with no success. Here is my problem:
    I have the main(), from there it's calls the class GetVar(), GetVar stores info in Class HousingForVar(), and finially, I have a class TryinToTalkToHousing() that I use to access HousingForVar()'s methods. I know I can use the keyword new but if I do that then it erases over the data I put in. Please can anyone help, this has been driving me nutz all day. Thank you in advance.
    Roman03
    ***EACH CLASS IS A DIFFERENT FILE****
    public class TestMain
         public static void main( String args[] )
              GetVar getVarible = new GetVar();
              getVarible.heroF();
    import java.util.Scanner;
    public class GetVar
         public void heroF()
              String someEntered;
              Scanner input = new Scanner( System.in);
              System.out.println("Enter a string: ");
              someEntered = input.next();
              HousingForVar houseForData = new HousingForVar(someEntered);
              System.out.printf("Retieved from Class GetVar, you entered: %s\n", houseForData.getCollectVar() );
    import java.util.Scanner;
    public class HousingForVar
         private String getData;
         public HousingForVar(String enterInfo)
              getData = enterInfo;
         public void setGetVar(String enterInfo)
              getData = enterInfo;
         public String getCollectVar()
              return getData;
    import java.util.Scanner;
    public class TryinToTalkToHousing
         public void someMeth()
              String getInfoFromHousing;          
              System.out.printf("Started out at TryinToTalkToHousing Class\n Retieved from Class GetVar from %s\n",
              houseForData.getCollectVar() );
    \* I know this doesn't work, but if I make a new object of the class HousingForVar it's going to write over my input, so what do I do? I am still learning, Please help*\

    I don't use 1.5, so you'll have to convert it back, but see if you can follow the flow of this
    import java.io.*;
    class TestMain
      GetVar getVarible;
      public TestMain()
        getVarible = new GetVar();
        getVarible.heroF();
        System.out.println("******");
        new TryinToTalkToHousing(this).someMeth();
      public static void main(String[] args){new TestMain();}
    class GetVar
      HousingForVar houseForData;
      public void heroF()
        try
          BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
          System.out.print("Enter a string: ");
          String someEntered = br.readLine();
          houseForData = new HousingForVar(someEntered);
          System.out.println("Retieved from Class GetVar, you entered: "+houseForData.getCollectVar()+"\n");
        catch(Exception e){e.printStackTrace();}
    class HousingForVar
      private String getData;
      public HousingForVar(String enterInfo)
        getData = enterInfo;
      public void setGetVar(String enterInfo)
        getData = enterInfo;
      public String getCollectVar()
        return getData;
    class TryinToTalkToHousing
      TestMain parent;
      public TryinToTalkToHousing(TestMain t){parent = t;}
      public void someMeth()
        System.out.println("Started out at TryinToTalkToHousing Class\n"+
        "Retieved from Class GetVar, you entered: "+parent.getVarible.houseForData.getCollectVar()+"\n");
    }

  • Use of swings- one class calling the gui class

    Hi,
    I have a class Manager and a class ManagerGUI.
    My ManagerGUI class looks somehting like this-
    public class ManagerGUI extends JFrame
    String name;
    JPanel namePanel;
    JTextField nameInput;
    JLabel nameLabel;
    Manager empAgent;
    ManagerGUI(Manager ea)
    super(ea.getLocalName());
    empAgent = ea;
    //make the name panel and add it to the topPanel.
    addListeners();
    getContentPane().add(topPanel, BorderLayout.CENTER);
    setResizable(false);
    }//end constructor.
    public void show()
    pack();
    super.setVisible(true);
    void addListeners()
    nameInput.addActionListener(new NameL());
    class NameL implements ActionListener
    public void actionPerformed(ActionEvent e)
    nameE = nameInput.getText();
    }//end class ManagerGUI.
    I have tried to seperate it out so that any changes can be easily implemented (although it perhaps is a long way of doing things).
    Now I have a class Manager that wants to call the GUI and then process the information got from the text field.
    I use the following lines to call the GUI class.
    manGui = new ManagerGUI(this);
    manGui.show();
    Is this the correct way of calling the GUI class?
    How do I get to use the variable nameE here, in the Manager?
    Thanks.

    Hi,
    I have no idea why you want to have an instance of Manager class in class ManagerGUI and an instance of ManagerGUI class in Manager class.
    I will create an instance of Manager in ManagerGUI and show the GUI there.
    In Manager you can create method that will accept the text from textfield in parameter.
    L.P.

  • Help: error: can not find the main class!

    when I run the class, the following error message comes up:
    java.lang.NoClassDefFoundError: j2sdk1/4/1
    and also a dialogue window (title is "java virtual machine launcher") comes up: could not find the main class, program will exit! After I click ok button, another error message shows up: Exception in thread "main" .
    Could anyone help me figure out what's wrong with my program? If you need any other informaiton, please email me: [email protected], Thanks a lot!!!

    Hi, thank you very much for your reply. Here is the program:
    import java.sql.*;
    import java.io.*;
    import java.util.*;
    import java.lang.Object;
    public class CatalogConnect{
    Statement stmt, st, mast, ques;
    ResultSet rset, orgset,maset, quesset;
    String organization = null;
    String sponsor = null;
    String interMethod = null;
    String year = null;
    String collection = null;
    String country = null;
    String countryName = null;
    String archNO = null;
    String codeBook = null;
    String td = null;
    String todate = null;
    String month = null;
    int studyID, quesID, sponsorID, orgID;
    public CatalogConnect(){
    connect();
    makeXMLFile();
    public CatalogConnect(String codeBk){
    codeBook = codeBk;
    connect();
    makeXMLFile();
    public void connect(){
    try{
    // DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
    // Class.forName(oracle.jdbc.driver.OracleDriver);
    Connection conn =
    DriverManager.getConnection ("jdbc:oracle:thin:@137.99.37.146:1521:ipoll",
    "catalog", "catalog");
    stmt = conn.createStatement ();
    st = conn.createStatement ();
    mast = conn.createStatement ();
    Connection conn2 =
    DriverManager.getConnection ("jdbc:oracle:thin:@137.99.36.171:1521:ipolljr2",
    "catalog", "catalog");
    ques = conn2.createStatement ();
    } catch(SQLException ex) {
    System.err.println("SQLException: " + ex.getMessage());
    public static void main (String args[]){
    CatalogConnect c = new CatalogConnect();
    public void makeXMLFile() {
    PrintWriter out = null;

  • HELP!!! - Can the ClientHandler class send the client a file to .....

    Can the ClientHandler class send the client a file to a specific location on the client's PC[e.g. c:\games\folder1] ?

    What's the definition of your ClientHandler class?
    You can send any file you want to a machine that supports a server that is able to write the files. Its all up to the target machine what it will allow you to do. Is your target machine running an FTP server? If so you can use the URL class to send files to it.
    Did you check out the Tivoli Remote Control application I suggested on your earlier thread?

  • Using a List as the value class of a Map - How?

    Hello,
    I have a managed-property of the following type
    Map<String, List<String>> myMap;How can I set the values for the List in the faces-config.xml?
    I tried sth like this, but this is no valid XML according to the schema.
    Any ideas?
    Regards,
    Jan
    <managed-property>
    <property-name>myMap</property-name>
      <property-class>java.util.TreeMap</property-class>
      <map-entries>
      <key-class>java.lang.String</key-class>
      <value-class>java.lang.ArrayList</value-class>
        <map-entry>
          <key>key1</key>
          <value>
          <list-entries>
            <value>value1</value>
            <value>value2</value>
          </list-entries>
          </value>
        </map-entry>
      </map-entries>
    </managed-property>

    You don't need a cfloop. Try an IN(...) clause instead.
    Obviously you have to validate that the #riderlist# is not empty
    first or the query will error.
    SELECT riderId,
    SUM(IIf(month(rideDate)=1, rideDistance, 0)) AS janSum,
    SUM(IIf(month(rideDate)=2, rideDistance, 0)) AS febSum,
    SUM(IIf(month(rideDate)=3, rideDistance, 0)) AS marSum,
    SUM(IIf(month(rideDate)=4, rideDistance, 0)) AS aprSum,
    SUM(IIf(month(rideDate)=5, rideDistance, 0)) AS maySum,
    SUM(IIf(month(rideDate)=6, rideDistance, 0)) AS junSum,
    SUM(IIf(month(rideDate)=7, rideDistance, 0)) AS julSum,
    SUM(IIf(month(rideDate)=8, rideDistance, 0)) AS augSum,
    SUM(IIf(month(rideDate)=9, rideDistance, 0)) AS sepSum,
    SUM(IIf(month(rideDate)=10, rideDistance, 0)) AS octSum,
    SUM(IIf(month(rideDate)=11, rideDistance, 0)) AS novSum,
    SUM(IIf(month(rideDate)=12, rideDistance, 0)) AS decSum
    FROM mileageLog
    WHERE riderId IN (<cfqueryparam value="#riderList#"
    cfsqltype="the column type here" list="true"> )
    AND Year(rideDate)=#useYear#
    GROUP BY riderId
    ORDER BY riderId

  • Using two versions of the one class together?? (I think)

    Hi, see the following small program, where the user can enter an int, and the program draws that amount of lines, joined together at a centre point. The user can then move these lines around the centre by dragging the red dot at the end of the lines.
    Anyway, what I want to be able to do, is have two different versions of this program running side by side, independently of each other. (ie one might have 4 lines, the other have 3). Each one, would also be able to read data from each other.
    Is this possible?
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class Lines4 extends JFrame implements MouseListener, MouseMotionListener {
    private int startx = 200;
    private int starty = 200;
    private JLabel statusBar;
    private Road roads[];
    private static final int roadLength = 100;
    private static final int circleRadius = 4;
    private Road movingRoad;
    public Lines4() {
    super("Lines4");
    String ret = JOptionPane.showInputDialog("How many roads are there?");
    int numPoints = Integer.parseInt( ret );
    double factor = 2.0 * Math.PI / ( numPoints ) ;
    roads = new Road[numPoints];
    for (int i=0; i<numPoints; i++){
    int x = (int)( roadLength * Math.cos( factor * i ) );
    int y = (int)( roadLength * Math.sin( factor * i ) );
    roads[i] = new Road( i, startx, starty, circleRadius, startx+x, starty+y );
    addMouseListener(this);
    addMouseMotionListener(this);
    statusBar = new JLabel();
    getContentPane().add(statusBar, BorderLayout.SOUTH);
    public void paint( Graphics g ) {
    g.clearRect( 0, 0, getWidth(), getHeight() );
    for (int i=0; i<roads.length; i++) {
    roads.draw( g );
    // MouseListener Event Handlers
    public void mouseClicked( MouseEvent e ){
    statusBar.setText( "Clicked at [" + e.getX() +
    ", " + e.getY() + "]" );
    public void mousePressed( MouseEvent e ){
    statusBar.setText( "Pressed at [" + e.getX() +
    ", " + e.getY() + "]" );
    for (int i=0; i<roads.length; i++) {
    if ( roads[i].onCircle( e.getX(), e.getY() ) ) {
    movingRoad = roads[i];
    public void mouseReleased( MouseEvent e ){
    statusBar.setText( "Released at [" + e.getX() + ", " + e.getY() + "]" );
    movingRoad = null;
    public void mouseEntered( MouseEvent e ){
    statusBar.setText( "Mouse in window" );
    public void mouseExited( MouseEvent e ){
    statusBar.setText( "Mouse outside window" );
    // MouseMotionListener event handlers
    public void mouseDragged( MouseEvent e ){
    statusBar.setText( "Dragged at [" + e.getX() +
    ", " + e.getY() + "]" );
    if ( movingRoad != null ) {
    movingRoad.x = e.getX();
    movingRoad.y = e.getY();
    repaint();
    public void mouseMoved( MouseEvent e ) {
    statusBar.setText( "Moved at [" + e.getX() +
    ", " + e.getY() + "]" );
    public static void main( String args[] ) {
    Lines4 app = new Lines4();
    app.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    app.setSize( 400, 400 );
    app.setVisible( true );

    You need to be very careful which project you open in which version.
    For 2014 make sure its on 2014.1 build 81.

  • LoadClass    (error loading a class which extends other class  at run-time)

    Hey!
    I'm using the Reflection API
    I load a class called 'SubClass' which exists in a directory called 'subdir' at run-time from my program
    CustomClassLoader loader = new CustomClassLoader();
    Class classRef = loader.loadClass("SubClass");
    class CustomClassLoader extends ClassLoader. I have defined 'findClass(String className)' method in CustomClassLoader.
    This is what 'findClass(String className)' returns:
    defineClass (className,byteArray,0,byteArray.length);
    'byteArray' is of type byte[] and has the contents of subdir/SubClass.
    the problem:
    The program runs fine if SubClass does not extend any class.
    If however, SubClass extends another class, the program throws a NoClassDefFoundError. How is it conceptually different?
    Help appreciated in Advance..
    Thanks!

    Because i'm a newbie to the Reflection thing, i'm notI don't see reflection anywhere. All I see is class loading.
    sure what role does the superclass play when i'm
    trying to load the derived class and how to get away
    with the errorWell... hint: all the superclass's stuff is not copied into the subclass.
    I am quite sure it fails to load the superclass because of classpath issues.

  • Instantiation of similar object over a super class deciding the sub class

    Hello all
    First, sorry if I'm duplicating an already answered question. I didn't searched very deep.
    Initial position:
    I have 2 Object (A1 and A2) which share the most (about 90%) of their instance variables an the associated methods. The values of the instance variables are retrieved in the real implementation from a stream. Depending of the data of the stream, I have to instantiate either a A1 or A2 object.
    A test implementation (using an int in case of the stream):
    The super class A:
    package aaa;
    public class A
      protected int version = -1;
      protected String name = null;
      protected AE ae = null;
      protected A()
      protected A(int v)
        // Pseudo code
        if (v > 7)
          return;
        if (v % 2 == 1)
          this.version = 1;
        else
          this.version = 2;
      public final int getVersion()
        return this.version;
      public final String getName()
        return this.name;
      public final AE getAE()
        return this.ae;
    }The first sub class A1:
    package aaa;
    public final class A1 extends A
      protected A1(int v)
        this.version = v;
        this.name = "A" + v;
        this.ae = new AE(v);
    }The second subclass A2:
    package aaa;
    import java.util.Date;
    public final class A2 extends A
      private long time = -1;
      protected A2(int v)
        this.version = v;
        this.name = "A" + v;
        this.time = new Date().getTime();
        this.ae = new AE(v);
      public final long getTime()
        return this.time;
    }Another class AE:
    package aaa;
    public class AE
      protected int type = -1;
      protected AE(int v)
        // Pseudo code
        if (v % 2 == 1)
          this.type = 0;
        else
          this.type = 3;
      public final int getType()
        return this.type;
    }To get a specific object, I use this class:
    package aaa;
    public final class AFactory
      public AFactory()
      public final Object createA(int p)
        A a = new A(p);
        int v = a.getVersion();
        switch (v)
        case 1:
          return new A1(v);
        case 2:
          return new A2(v);
        default:
          return null;
    }And at least, a class using this objects:
    import aaa.*;
    public final class R
      public static void main(String[] args)
        AFactory f = new AFactory();
        Object o = null;
        for (int i = 0; i < 10; i++)
          System.out.println("===== Current Number is " + i + " =====");
          o = f.createA(i);
          if (o instanceof aaa.A)
            A a = (A) o;
            System.out.println("Class   : " + a.getClass().getName());
            System.out.println("Version : " + a.getVersion());
            System.out.println("Name    : " + a.getName());
            System.out.println("AE-Type : " + a.getAE().getType());
          if (o instanceof aaa.A2)
            A2 a = (A2) o;
            System.out.println("Time    : " + a.getTime());
          System.out.println();
    Questions:
    What would be a better way to encapsulate the logic into their respective objects ? Is there a way to let the super class A itself identify the type of the object and then extend from A to either A1 or A2 ?
    Thanks in advance
    Andreas

    Hello jduprez
    First, I would thank you very much for taking the time reviewing my problem.
    Just for the record: have you considered regular serialization? If you control the software at both ends of the stream, you could rely on standard serialization mechanism to marshall the objects and unmarshall them automatically.In my case, I can't control the other site of the stream. At the end, the data comes from a FileInputStream and there aren't objects on the other site, only pur binary data.
    - It seems you have one such factory class. Then you already have encapsulated the "determine class" logic, you don't need to add such logic in superclass A.I thought from an OO view, that the super class A is responsible of doing that, but that's where the problem starts. So at the end, it's better doing it in the factory class.
    - A itself encapsulates the logic to load its own values from the stream.
    - A1 and A2 can encapsulate the logic to load their own specific value from a stream (after the superclass' code has loaded the superclass' attributes values).
    My advise would be along the lines of:
    public class A {
    .... // member variables
    public void load(InputStream is) {
    ... // assign values to A's member variables
    // from what is read from the stream.
    public class A1 extends A {
    ... // A1-specific member variables
    public void load(InputStream is) {
    super.load(is);
    // now read A1-specific values
    public class AFactory {
    public A createA(InputStream is) {
    A instance;
    switch (is.readFirstByte()) {
    case A1_ID:
    a = new A1();
    break;
    case A2_ID:
    a = new A2();
    break;
    a.load(is);
    }The example above assumes you have control over the layout of the data in the stream (here for a given A instance, the attributes defined in A are read first, then come the subclass-specific attributes.
    The outcome is: you don't have to create a new A( ) to later create another instance, of a subclass.I like the idea. In the AFactory, is the "A instance;" read as "A a;" ?
    Is there a way to let the super class A itself identify the type of the object and then extend from A to either A1 or A2 ?Note I initially read this question as "can an instance of a class mutate into another class", to which the answer is no (an object has one single, immutable class; it is an instance of this class, and of any superclass and superinterface, but won't change its class at runtime).Yes, I have been thinking about a way for mutating into a subclass to keep the already initialized values from the A class without copying or parsing again. But preventing an instance of an A class will be my way. So, in this aspect, Java didn't changed in the last 10 years... It's a long time ago I've used Java for some real projects.
    You can, however, create an instance of another class, that copies the values off a priori A instance. Your example code was one way, another way could be to have a "copy constructor":
    public class A {
    public A(A model) {
    this.att1 = model.att1;
    this.att2 = model.att2;
    public class A1 {
    public A1(A model) {
    super(model);
    ... // do whatever A1-specific business
    )Still, I prefer my former solution less disturbing: I find the temporary A instance redundant and awkward.Nice to know. I prefer the first solution too.
    Thank you again for the help and advices. My mind is searching sometimes for strange solutions, where the real is so close ;-)
    Andreas

  • Warning :: Derived class hides the base class virtual function

    We are porting from CC5.3 to CC5.8 compiler with Sun Studio one compiler. After plenty of hurdles we are in the final stage of removing the warning messages... Amoung the plenty the following one is very common and in different files. Why am I getting this error in 5.8 and not in 5.3 compiler....
    Warning: derived_Object::markRead Hides the virtual function base_Object::markRead(ut_SourceCodeLocation&) const in a virtual base
    From this it is easily understandable that the base class mark read was hidden by derived class markRead... when we drive and override the derived class function.... It is all over the place....
    Thank you,
    Saravanan Kannan
    //public: using xx_Object :: markRead;
    virtual void markRead() const;

    The Sun C++ FAQ discusses the warning message:
    http://developers.sun.com/prodtech/cc/documentation/ss11/mr/READMEs/c++_faq.html#Coding1
    Notice that warnings are not necessarily errors. But I applaud your desire to fix the code so that it generates no warnings. I wish more of our customers could be persuaded to do the same. :-)
    C++ 5.3 issues this warning, by the way. Example:
    struct B { virtual int foo(int); };
    struct D : B { virtual int foo(double); }; // line 2
    D d;
    line 2: Warning: D::foo hides the virtual function B::foo(int).
    If for your particular code you do not see a warning with C++ 5.3, it would be due to a bug in C++ 5.3 that was later fixed.

Maybe you are looking for

  • IMac on Netgear X104 and Airport Extreme intermittently loses IP address

    We have a Netgear X104 plugged into an Airport Extreme Base Station. Another X104 (which carries network information through the household electrical wiring) is plugged in for a networked iMac with OS X v 10.5.4. The network works flawlessly, but eve

  • Oracle 10g database growing day by day

    Oracle 10g database database is growing day by day. I would like to know what is inserting into database Can you please let me know

  • Backward compatibility with iWork '06

    does anyone know if iWork '08, specifically Pages, will open '06 files? if it can't, i don't know that i want to upgrade...i would rather not download the trial version. thanks in advance.

  • Sound levels are not accurate

    Ok, so I added my video to the dvd and then in the main menu i added a music track but the music trac s blaring and then when the video plays the sound from that is much quieter. How do i bring down the levels for the music track i have just added to

  • MACBOOK PRO WITH YOSEMITE X CANNOT DRAG AND DROP EMAILS FROM INBOX TO OTHER FOLDERS WHY?

    I have just bought a replacement macbook pro and installed the backup from my old machine so everything looks and feels the same, however the above problem has appeared. I can move files using "move to" but find this method clunky. Can this be easily