Inheritance constructor question

Hi
I am having trouble understanding how the superclasses constructor works in inheritance:
Please look at the following code:
public class mySuperClass
     mySuperClass ()
          System.out.println("super1");
public class myClass extends mySuperClass
     myClass ()
          System.out.println("hello1");
     myClass (int q)
          System.out.println("hello2");
public static void main(String[] args)
          myClass o = new myClass ();
          myClass o = new myClass (3);
When I run this program the console results are:
super1
hello1
super1
hello2
Why does the constructor of the super class run even when I overload it?
Thanks
Aharon

I think you meant to write "Why does the constructor of the super class run even when I overrideit?"
And the point is you can't override a constructor (technically, they are not even methods). A constructor in a derived class (MyClass) must call a constructor in its superclass (MySuperClass ). If you do not explicitly call one:
MyClass (int q) {
    super(...arguments...); // <---
    System.out.println("hello2");
}There will be an attempt to implicitly to invoke super();

Similar Messages

  • Why aren't inherited constructors returned?

    Let's say I have an abstract class that defines a public constructor, and a different class that extends this abstract class. I'd like to use reflection to instantiate an object of the subclass using the constructor of the parent class. If this is possible to do in code, why is it not possible to do at run-time? (Or am I hopefully missing something, and there is in fact a way to do this?) If Class.getMethods() will return inherited methods, why won't Class.getConstructors() return inherited constructors?

    Let's say I have an abstract class that defines a
    public constructor, and a different class that extends
    this abstract class. I'd like to use reflection to
    instantiate an object of the subclass using the
    constructor of the parent class. If this is possible
    to do in code, It's not possible to do it "in code" (by which I assume you mean the "normal" way, without reflection). As the other poster said, constructors are not inherited.
    If you're specifically interested in reflection, the following may not be particularly applicable to your current problem. However, you'll need to understand these rules anyway...
    Here are the rules for constructors--"ctors" because I'm lazy. Also, because I'm lazy, "super(...)" and "this(...)" mean any super or this call, regardless of how many args it takes, including those that take no args.
    1) Every class has at least one ctor.
    1.1) If you do not define an explicit constructor for your class, the compiler provides a implicit constructor that takes no args and simply calls super().
    1.2) If you do define one or more explicit constructors, regardless of whether they take args, then the compiler no longer provides the implicit no-arg ctor. In this case, you must explicitly define a public MyClass() {...} if you want one.
    1.3) Constructors are not inherited.
    2) The first statement in the body of any ctor is either a call to a superclass ctor super(...) or a call to another ctor of this class this(...) 2.1) If you do not explicitly put a call to super(...) or this(...) as the first statement in a ctor that you define, then the compiler implicitly inserts a call to super's no-arg ctor super() as the first call. The implicitly called ctor is always super's no-arg ctor, regardless of whether the currently running ctor takes args.
    2.2) There is always exactly one call to either super(...) or this(...) in each constructor, and it is always the first call. You can't put in more than one, and if you put one in, the compiler's implicitly provided one is removed.

  • Inheritance Constructor error

    Hi guys, having a spot of bother with a constructor of a sub-class.
    What i am doing is making a super class... Person and a subclass... Administrator
    When i am coding my constructor for the administrator every inherited field constructs but my local one does not
    The error i get is on the constructor parameter, Cannot find symbol : constructor Person. class: Person
    I think it may be something to do with java not knowing what constructor to use
    Heres my code
    Personpublic abstract class Person{
        // TO DO
        // READ THE COMMENTS AND COMPLETE
        //Attributes
       public String name;
       public String address;
       public String sex;
       public int age;
           public Person(String name, String address, String sex, int age) {
            this.name = name;
            this.address = address;
            this.sex = sex;
            this.age = age;
        }Administrator
    public class Administrator extends Person {
        // Attributes
        private String type;
        // TO DO
        // READ THE COMMENTS AND COMPLETE
         * Constructor
         * @param name name of the administrator
         * @param address address of the administrator
         * @param gender sex of the administrator
         * @param age age of the administrator
         * @param type member type of the administrator
        public Administrator(String name, String address, String gender,
                int age, String type) {
            this.name=name;
            this.address=address;
            this.sex= gender;
            this.age=age;
            this.type=type;
        }

    If you don't explicity invoke a super constructor, the compiler inserts a call to the no-arg c'tor: super(); If your parent class does not have such a c'tor, that's an error. You'll need to add a call to
    super(name, age, gender);
    // or whatever parameters the parent's c'tor actually takesas the first line of your child class c'tor.

  • Urgent constructor question..

    I'm trying to call this Flower class in another class called Garden, in which I created a new Flower by using a statement
    private Flower lastflower;
    and it's saying it cannot find the symbol - constructor Flower.
    Can anyone tell me why and help correct this problem?
    Below is the code for my Flower class.
    Any help is really appreciated, it's for my Java class!
    import objectdraw.*;
    import java.awt.*;
    * Write a description of class Flower here.
    * @author (your name)
    * @version (a version number or a date)
    public class Flower
        protected FilledOval dot;
        protected FilledRect stem;
        protected FilledOval petal1;
        protected FilledOval petal2;
        protected static final int boundary = 100;
        protected RandomIntGenerator colorGen =
                new RandomIntGenerator(0,255);
        protected Color petalColor;
        protected Boolean flowerContains=false;
        private DrawingCanvas canvas;
        public void changeColor(){
        dot = new FilledOval(150,150,15,15, canvas);
        dot.setColor(Color.YELLOW);
        petalColor = new Color(colorGen.nextValue(),
                                    colorGen.nextValue(),
                                    colorGen.nextValue());
        petal1.setColor(petalColor);
        petal2.setColor(petalColor);
        public void grow(Location point){
        stem = new FilledRect (dot.getX()+3, dot.getY()+10, 10, 10, canvas);
        stem.setColor(Color.GREEN);
        if (dot.getY()>boundary){
            dot.move(0,-4);
        else{
         petal1 = new FilledOval(dot.getX()-12, dot.getY()-25, 40,70,canvas);
         petal2 = new FilledOval(dot.getX()-25, dot.getY()-10, 70,40,canvas);
         dot.sendToFront();
         stem.sendToBack();
         petal1.setColor(petalColor);
         petal2.setColor(petalColor);
        public Boolean flowerContains(Location point){
            if (petal1.contains(point)){
                return true;
            else if (petal2.contains(point)){
                return true;
            else if (dot.contains(point)){
                return true;
            else{
                return false;
    }

    I don't care how fucking urgent you think it is, it isn't to us. We will answer your question when and how we feel llike it. Have some manners and if you must, then bump your original post. Don't create another time wasting piece of cr&#97;p!

  • Static Inheritance, Constructors --- Classes as objects

    First I asked myself why constructors are not inherited.
    Then I asked myself why Static Methods are not inherited.
    And it all seems to come down to, why Classes are not objects in Java as they are in Smalltalk?
    Is there any reason I'm missing?
    I would love at least inheritable static methods.

    That's OK, but that method would not be inherited, and would execute in the context of the superclass.
    Picture this (a simple "template method"):
    class SuperClass {
         public static void staticMethod() {          
              System.out.println("Static in SuperClass");
              other();          
         public static void other() {          
              System.out.println("other in SuperClass");
    class SubClass extends SuperClass{
         public static void other () {
              System.out.println("other in SubClass");
    Here, I just want to redefine other() in SubClass, but it calls the SuperClass version.
    Let's test:
    public class Test {
         public static void main(String[] args) throws DatabaseErrorException, TableUpdateException {
              SuperClass.staticMethod();
              SubClass.staticMethod();
    Output:
    Static in SuperClass
    other in SuperClass
    Static in SuperClass
    other in SuperClass
    First line calls static in SuperClass, which calls other (found in SuperClass and executed), the output from other is second line.
    Then, the third line shows calling staticMehod in SubClass, which doesn't redefine it, and executes the SuperClass version, that's ok, but when staticMethod calls other, it doesn't look for it in SubClass, but it directly executes the one in SuperClass (which is shown in line 4).

  • Inheritance, constructor and error handling

    I always got problems while trying to call the constructor of a class inheriting from an other.
    I have a concrete problem that is, I think, easy to solve, but I dont find the answer.
    Here is my method that throws an exception:
    public void aMethod() throws MyException
         doSomething();
         if ( errorOccured )
              throw new MyException( "An error occured");
    ...And here is the code of MyException (and here is the error I think):
    public class MyException extends java.lang.Exception
    }When javacing the class containing the first bloc of code I get something like:
    TheClass.java:103: cannot resolve symbol
    symbol  : constructor MyException  (java.lang.String)
    location: class MyException
                            throw new MyException( "An error occured" );
                                  ^If you know how to do that without error. Please give me codes, I will use them as example.
    Thx

    You are correct about where the error is. Although Exception has a constructor "new Exception(String)", if you create a subclass of Exception then you must define this constructor if you want to use it. Not difficult to do:
    public class MyException extends java.lang.Exception{
      public MyException(String s) {
        super(s);

  • Inheritance architecture question

    Hello,
    I've an architecture question.
    We have different types of users in our system, normal users, company "users", and some others.
    In theory they all extend the normal user. But I've read alot about performance issues using join based inheritance mapping.
    How would you suggest to design this?
    Expected are around 15k normal users, a few hundred company users, and even a few hundred of each other user type.
    Inheritance mapping? Which type?
    No inheritance and append all attributes to one class (and leave these not used by the user-type null)?
    Other ways?
    thanks
    Dirk

    sorry dude, but there is only one way you are going to answer your question: research it. And that means try it out. Create a simple prototype setup where you have your inheritance structure and generate 15k of user data in it - then see what the performance is like with some simple test cases. Your prototype could be promoted to be the basis of the end product if the results or satisfying. If you know what you are doing this should only be a couple of hours of work - very much worth your time because it is going to potentially save you many refactoring hours later on.
    You may also want to experiment with different persistence providers by the way (Hibernate, Toplink, Eclipselink, etc.) - each have their own way to implement the same spec, it may well be that one is more optimal than the other for your specific problem domain.
    Remember: you are looking for a solution where the performance is acceptable - don't waste your time trying to find the solution that has the BEST performance.

  • Constructor question?

    I am working on a class called Firm and it has an array of employee objects as its data field. Its constructor has an array of employee objects as its parameter: it initializes the data field array by copying references from the parameter array in a loop. Its main method creates one or two HourlyEmployee objects and one or more exemptEmployee objects. Then it calls setPay for one HourlyEmployee object and one ExemptEmployee objects and prints the results. Then it calls methods setPay and toString for these two objects (calling println, annotate this part of processing so that the output is readable).
    What I have so far is, Employee being an abstract class that has a Constructor, and methods setPay(), getPay(), and toString. Subclasses HourlyEmployee and ExemptEmployee each with their own constructors and methods getPay() and setPay() along with toString() methods.
    Currently this is what I have for code for my Firm class:
    public class Firm
    private Employee[] empObj;
    Firm(Emp[] empObj)
    for(int i = 0;i<empObj.length;++i)
    arrObj=empObj;
    }Does my constructor have an array of employee objects as its parameters? Do I need to create an Object array[] arrObj?

    if Firm's constructor is being passed an Employee array, then just save that reference.
    public class Firm
      private Employee[] empObj;
      public Firm(Emp[] empObj)
        this.empObj = empObj;
    }Alternatively, you may wish to copy the parameter so that changes to the original (made outside by the guy who passed it to you, for example) don't affect it. In that case, change Firm's constructor to do this:
    this.empObj = new Employee[empObj.length];
    for (int i = 0; i < empObj.length; ++i)
      this.empObj[i] = empObj;
    // or, you may even want to "deep-copy" it like this, if you created
    // a "copy-constructor" or "clone" method:
    this.empObj[i] = new Employee(empObj[i]);
    //or
    this.empObj[i] = (Employee) empObj[i].clone();

  • Inheritance related question

    class a{
         public void meth()
              System.out.println("In a");
    class b extends a{
         public void meth()
              System.out.println("In b");
    public class Test extends b{
         public static void main(String[]a)
    }can i call the a's meth() from Test without creating an instance of a? This might be a simple question and i think i cant create it, but if this is possible please tell me how to do it. also im not referring to runtime polymorphism. without using runtime polymorphism, can i access a's meth()? i know by calling super.meth() in b's meth() will solve it but i do not want to go that way.
    Thanks in advance,
    Geet

    meth is not a static method of the class a, so you can't really call it without instantiating class a.
    If you meant "can I call method meth in class a with an instance of class b?",(note that an instance of b is an instance of a) the answer is no as well, because your method from class b has overridden it... Note that you CAN call the method from class a from within class b (but not from Test), by using the keyword super.

  • Catching exception from inherited constructor

    Hi all,
    If I'm extending a class and the constructor of the parent class throws an exception, is there any way to catch that exception in my constructor? What I would like to do is something like this.
    public class MyClass extends OtherClass {    // the constructor for OtherClass throws an exception
        public MyClass() {
            try {
                super();
            } catch (Exception e) {}
    }But of course you can't do that because super() has to be the first command in the method. Is there any other way to accomplish this? My objective is to chain this exception to a different type of exception.

    Write a factory method? For example:
    class ABCException extends Exception {}
    class XYZException extends Exception {}
    class OtherClass {
        public OtherClass()  throws ABCException {
            throw new ABCException();
    class MyClass extends OtherClass {    // the constructor for OtherClass throws an exception
        protected MyClass() throws ABCException {
           super();
        public static MyClass instance() throws XYZException {
            try {
                return new MyClass();
            } catch (ABCException e) {
                throw new XYZException();
    }

  • Constructor question - dealing with protected methods

    Hi all, I'm trying to run a protected method, got somewhere by making the class a subclass - but not too sure about where to put the constructor for a class I'm trying to use (IQRegister). Can anyone help and point me in the right direction as to what I did wrong?
    public class Registration extends IQRegister {
    //Create new instance of ConnectionBean
    ConnectionBean conBean = new ConnectionBean();
    InfoQueryBuilder iqb = new InfoQueryBuilder();
    InfoQuery iq;
    //IQRegisterBuilder iqRegb = new IQRegisterBuilder();
    public Registration( IQRegisterBuilder iqRegb ) {
    super( iqRegb );
    //This constructor needs to go somewhere that will work>>>>>>>>>>>>>>
    IQRegister iqReg = new IQRegister( iqRegb );
    public void regUser() {
    String server = JOptionPane.showInputDialog( "Enter Server address" );
    InetAddress inetaddress;
    try {
    conBean.connect( inetaddress = InetAddress.getByName( server ));
    catch( UnknownHostException unknownhostexception ) {
    Object aobj[] = {
    "Cancel", "OK"
    int i = JOptionPane.showOptionDialog(null, "Retry Server?", server +
    ": Not Responding", -1, 2, null, aobj, aobj[1]);
    if( i == 1 )
    regUser();
    System.out.println( "Cannot resolve " + server + ":" + unknownhostexception.toString ());
    return;
    catch( IOException ioexception ) {
    Object aobj1[] = {
    "Cancel", "OK"
    int j = JOptionPane.showOptionDialog( null, "Cannot Connect to:",
    server,-1, 2, null, aobj1, aobj1[1] );
    if( j == 1 )
    regUser();
    System.out.println( "Cannot connect " + server);
    return;
    System.out.println( "Registering User" );
    registrationProcess();
    public void registrationProcess () {
    try {
    //Need to getXMLNS packet method getXMLNS() is protected
    iqReg.getXMLNS();
    catch ( InstantiationException e ) {
    System.out.println( "Error in building Registration packet" );
    String username = JOptionPane.showInputDialog( "Enter: Username" );
    String password = JOptionPane.showInputDialog( "Enter: Password" );
    ERROR:
    Registration.java:108: cannot resolve symbol
    symbol : variable iqReg
    location: class Registration
    iqReg.getXMLNS();
    ^
    1 error
    Thanks again :)

    Made some changes to code but getting some varied error here:
    Registration.java:31: <identifier> expected
    iqReg = new IQRegister( iqRegb );
    ^
    Registration.java:31: cannot resolve symbol
    symbol : class iqReg
    location: class Registration
    iqReg = new IQRegister( iqRegb );
    ^
    Registration.java:104: cannot resolve symbol
    symbol : variable iqReg
    location: class Registration
    iqReg.getXMLNS();
    ^
    3 errors
    CODE:
    public class Registration extends IQRegister {
    //Create new instance of ConnectionBean
    ConnectionBean conBean = new ConnectionBean();
    InfoQueryBuilder iqb = new InfoQueryBuilder();
    InfoQuery iq;
    //IQRegisterBuilder iqRegb = new IQRegisterBuilder();
    //This constructor problem here>>>>>>>>>>>>
    iqReg = new IQRegister( iqRegb );
    public Registration( IQRegisterBuilder iqRegb ) {
    super( iqRegb );
    .......same code..... as above....
    Thank you so much for the guidance..

  • Overloading constructor question

    The following douse not seem to work:-
    class A {
         A( int i ) {
              System.out.println( "A constructor" + i );
    class B {
         B( int i ) {
              System.out.println( "B constructor" + i );
    class C extends A {
         C () { // line 17
              System.out.println( "C constructor" );
         public static void main( String[] args ) {
              C c = new C();
    It complaines at line 17
    A(int) in A cannot be applied to ()
    C () {
    ^
    This has totaly bafeld be. I thought it was OK to add overloaded constructors in inheratid classes but it seems to be complaining that I am replacing C(int) wit C(), i.e. the constructor in the subclass has diferent arguments. surly this should simply add an overloaded constructer?
    Ben

    The first statement in every constructor must be a call to either a) another constructor in that class or b) a constructor of the super class. If you do not specify a call to either, then the compiler automatically will insert a call to the no argument constructor of the super class. Since there isn't a no-arg constructor in A, the compiler complains that you are calling the A(int) constructor with no arguments. You need to either add a no argument constructor to A, or you need to call the A(int) constructor from the C constructor with some default value.
    In case you didn't know, to call a super constructor from a subclass, you use the super keyword.
    Example:
    class A {
        A(int i) {}
    class B extends A {
        B() {
            super(2);  //This call the A(int) constructor.
    }

  • Constructor question.Help!

    Hi,
    I need help!I've been trying to do this for several hours now.
    My program takes in parameters a file cellSig.txt and a int in the main program and the int gives the number of for loops that need to be run.Now in the for loop,I have a constructor for class ranData.
    for(int model = 0;model<= cross; model++){
    ranData objData = new ranData(filename);
    }//cross is the parameter int given by user
    ranData basically takes the main file cellSig.txt and randomises and divides into 2 other files.It is vital that there should be different files for every 'for' loop.
    However I compile and
    ./ranData.java:5: illegal start of type
    try{
    ^
    ./ranData.java:40: <identifier> expected
    ^
    keyInput.java:18: cannot resolve symbol
    symbol : constructor ranData (java.lang.String)
    location: class ranData
    ranData objData = new ranData(filename);
    I'm posting the ranData.java code below.Pls help..I'm not sure what is wrong.
    import java.io.*;
    import java.util.*;
    public class ranData{
         ArrayList list = new ArrayList();
         try{
         BufferedReader in = new BufferedReader(new FileReader(filename));
         String FileToRead = in.readLine();
         while(FileToRead!= null){
              list.add(FileToRead);
              FileToRead = in.readLine();
         in.close();
         in = null;
         Collections.shuffle(list);
         List trainList = list.subList(0,2000);
         List testList = list.subList(2000,list.size());
         BufferedWriter  objBW =  new BufferedWriter(new FileWriter("cellSig.names"));
         BufferedWriter  objBWt =  new BufferedWriter(new FileWriter("cellSig.names"));
         Iterator x = trainList.iterator();
         Iterator y = testList.iterator();
         String tmp = "";
         String temp = "";
         while(x.hasNext()){
              tmp =(String) x.next() ;
              objBW.write(tmp);
              objBW.newLine();
         while(y.hasNext()){
              temp = (String)y.next() ;
              objBWt.write(temp);
              objBWt.newLine();
         objBW.close();
         objBWt.close();
         objBW = objBWt = null;
         x = y = null;
         }catch(IOException e){
         System.out.println(e);
    [\code]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    public RanData(String filename){     
         Filename = filename;
         try{
         BufferedReader in = new BufferedReader(new FileReader(Filename));
         String FileToRead = in.readLine();You are closing the constructor and start coding again without declaring the try catch within a method. Try this:
    import java.io.*;
    import java.util.*;
    public class RanData{
         ArrayList list = new ArrayList();
         public String Filename;
         public RanData(String filename){     
         Filename = filename;
         try{
         BufferedReader in = new BufferedReader(new FileReader(Filename));
         String FileToRead = in.readLine();
         while(FileToRead!= null){
              list.add(FileToRead);
              FileToRead = in.readLine();
         in.close();
         in = null;
         Collections.shuffle(list);
         List trainList = list.subList(0,2000);
         List testList = list.subList(2000,list.size());
         BufferedWriter  objBW =  new BufferedWriter(new FileWriter("cellSig.names"));
         BufferedWriter  objBWt =  new BufferedWriter(new FileWriter("cellSig.names"));
         Iterator x = trainList.iterator();
         Iterator y = testList.iterator();
         String tmp = "";
         String temp = "";
         while(x.hasNext()){
              tmp =(String) x.next() ;
              objBW.write(tmp);
              objBW.newLine();
         while(y.hasNext()){
              temp = (String)y.next() ;
              objBWt.write(temp);
              objBWt.newLine();
         objBW.close();
         objBWt.close();
         objBW = objBWt = null;
         x = y = null;
         }catch(IOException e){
         System.out.println(e);
    }I also reccomend you to read a good Java beginners books

  • Inheritance/Overloading Question

    Hi,
    Can someone please explain why the following piece of code would fail to compile:
    class A
      void m1(int a)    { System.out.println("A"); }
    class B extends A
      void m1(double b) { System.out.println("B"); }
    class C extends B
      void m1(float c)  { System.out.println("C"); }
    class D
      public static void main (String[] args) {
        int i=10;
        C c = new C();
        c.m1(i);
    D.java:28: reference to m1 is ambiguous, both method m1(int) in A and method m1(float) in C match
    c.m1(i);
    From my understanding, B overloads the method m1 of A, and C did likewise. And when C extends B, it inherits the version of m1 in A and B. So C should have 3 versions of m1 available to it, just like this code:
    class C
      void m1(int a)    { System.out.println("A"); }
      void m1(double b) { System.out.println("B"); }
      void m1(float c)  { System.out.println("C"); }
    }Why then the compiler could not decide which method to invoke ? Another strange thing is that if the version of m1 of A and C where to be interchanged, the compiler will not complain.
    Thanks.

    The behaviour of the compiler is correct according to the JLS (par 15.12.2.2). The problem is that there is no most specific method. You need to know that the type of the class in which the method declaration occurs plays a role just as much as the type of the parameters when choosing the most specific method.
    Let us look at the specific case. I will discard the method in class B because it does not affect the result. Thus, we have two choices:
    1) A.m1(int) is not more specific than C.m1(float) because A cannot be converted to C by method invocation conversion.
    2) C.m1(float) is not more specific than A.m1(int) because float cannot be converted to int by method invocation conversion.
    (Look in par 5.3 for the precise definition of method invocation conversion. However, it is pretty straight forward what it means.)
    Thus, neither A.m1(int) nor C.m1(float) is more specific and therefore any call to C.m1 will be ambigious.

  • Inheritance/Abstraction question

    Ok here is what I currently have. I have a base class, ORDERFROM, which I have made abstract. Then I have an interface, ORDERFORM_ACTIONS, whcih defines actions for an order form. Then I have a class ORDERFORM1. Is there a way to add some more abstraction to my order form family tree so I can have default methods with no parmeters? I am looking for a way to keep from having to implement all non parameter methods again for every new order form. I know they have to be implented in the base class for this to happen but what if the location changes? Keep in mind the location of the data items on the order from will change from revision to revision. Here is what the code structure looks like
    public interface OrderFormActions{
       public boolean placeOrder();
       public String getName();
       public String getPhone();
    public abstract class OrderForm implements  OrderFormActions{
      public OrderForm(){
      public String getName(int row, int col){
          String name = getCell(row, col);
      public String getPhone(int row, int col){
          String phone = getCell(row,col);
      public boolean placeOrder(){
    public class OrderForm1 extends OrderForm{
      public OrderFrom1(){
         super();
      public String getName(){
        int row = 1;
        int col =  2;
        return super.getName(row,col);    // I know super is not needed used for illistration
      public String getPhone(){
        int row = 4;
        int col = 12;
        return super.getPhone(row, col);  // I know super is not needed used for illistration
    }Ideas? As abstract as you can go?

    I mean the interface methods have to implented in
    some class. And if I don't want have to implement
    all the interface methods in every inherited class
    then I have will have to implement them in thebase
    class. (Low cuppeling, high conhesiveness)Then, either you should not have an inerface with
    th all those methods, or you should have an adapterThats totally wrong. Parent classes behavior is not governed by the sub classes. refer to Dependency Inversion Principle
    http://www.eventhelix.com/RealtimeMantra/Object_Oriented/dependency_inversion_principle.htm
    class that provides default behaviour from where
    your classes can inherit or you should put those
    default behaviour up in the class hierachy.Now thats an even worse advice. Under what conditions would you provide an adapter. This particular scenario is not one of them. refer to Software open closed principle.
    >
    May the code be with you.If you do things like this I guess the code would not be with you.

Maybe you are looking for

  • ICloud Photo Library & Family Sharing

    Hi there, is there a way to share the "iCloud Photo Library" with Family Sharing ? Since iOS 8 do not allow to use "Share my location" on multiple devices a.k.a. "Find my Friends" (Me & my wife use one iOs account) I have to use two accounts with Fam

  • Xmonad Magnifier conflicts with LayoutCombinators?

    Has anyone else noticed that using the Magnifier Layout together with the layoutCombinator does not work? The magnify toggle works but cycleThroughLayouts does not. If I remove maximizeVertical I can cycle fine. Here is my layout hook: myLayoutHook =

  • When you expand to show local and remote sites, in DW CS6 how do I get the local to be on the left?

    When you expand to show local and remote sites, in the previous verions of DW, the files type (local or remote) selected when not seeing both, automatically came up on the left.  I liked local when I am editing and when I am ready to upload I expand

  • Blinking advertising

    Hi Guys! I have realized a blinking advertising using a very simple xlet wich extends HComponent and rewriting the paint method so that the advertising message pops-up for 5 seconds and disappear for 10 seconds. I would like to add a small sound to t

  • Hello, how to unlock the iphone 4.

    my friend have bought a iphone 4 in LA, BestBuy, when he came to UK, he switch the carrier into the Vodafone, the phone can't read it, what wrong?