Click here to Skip to main content
15,887,683 members
Home / Discussions / Java
   

Java

 
AnswerRe: struts Pin
Richard MacCutchan21-Apr-13 22:36
mveRichard MacCutchan21-Apr-13 22:36 
AnswerRe: struts Pin
Shubhashish_Mandal25-Apr-13 21:22
professionalShubhashish_Mandal25-Apr-13 21:22 
Questionseparate logger configuration for each IDs Pin
sandeep m20-Apr-13 20:02
sandeep m20-Apr-13 20:02 
AnswerRe: separate logger configuration for each IDs Pin
Richard MacCutchan20-Apr-13 23:35
mveRichard MacCutchan20-Apr-13 23:35 
AnswerRe: separate logger configuration for each IDs Pin
jschell21-Apr-13 6:10
jschell21-Apr-13 6:10 
AnswerRe: separate logger configuration for each IDs Pin
TorstenH.26-Apr-13 2:08
TorstenH.26-Apr-13 2:08 
SuggestionPolymorphism Java Programming Help Pin
jude martin 9920-Apr-13 17:00
professionaljude martin 9920-Apr-13 17:00 
GeneralRe: Polymorphism Java Programming Help Pin
Richard MacCutchan21-Apr-13 0:36
mveRichard MacCutchan21-Apr-13 0:36 
You need to add constructors to your subclasses that take the animal's name and likes, then you can use the generic methods for any animal even if you do not know its class. Something like:
Java
import java.io.*;
import java.util.Scanner;

public class Test {

    public static void main(String [] args) {
    
        Animal[] zoo = new Animal[3];
        Animal a = new Animal("Generic Animal");
        a.displayName();
        
        Cat c = new Cat("Fluffy");
        c.displayName();
        
        zoo[0] = new Dog("Scooby-Doo");  // a dog
        
        zoo[1] = new Cat("Mittens");  // a cat
        for (int i = 0; i < 2; i++)
        	zoo[i].displayName();  // polymorphic calls
    }
}

// Superclass Animal
 
public class Animal {

    protected String name;
    protected String likes;

    public Animal(String newname, String what) {
        name = newname;
        likes = what;
    }

    public Animal(String newname) {
        this(newname, "everything");
    }

    public void displayName() {
        System.out.println("My name is " + name + " and I like " + likes);
    }
}

// Subclass Cat
public class Cat extends Animal {

    public Cat(String newname) {
        super(newname, "to drink milk");
    }
}

// Superclass Dog
public class Dog extends Animal {

    public Dog(String newname) {
        super(newname, "to eat bones");
    }
}

As you can see you can extended it by adding more common functionality to the superclass, but this should give you some ideas to work with.
Use the best guess

QuestionJava Linked Lists (JAVA Beginner in need of help) Pin
jude martin 9920-Apr-13 16:38
professionaljude martin 9920-Apr-13 16:38 
AnswerRe: Java Linked Lists (JAVA Beginner in need of help) Pin
Richard MacCutchan20-Apr-13 23:30
mveRichard MacCutchan20-Apr-13 23:30 
AnswerRe: Java Linked Lists (JAVA Beginner in need of help) Pin
Varad Velingkar23-Apr-13 7:41
Varad Velingkar23-Apr-13 7:41 
GeneralRe: Java Linked Lists (JAVA Beginner in need of help) Pin
sriniprabhu27-Apr-13 1:58
sriniprabhu27-Apr-13 1:58 
AnswerRe: Java Linked Lists (JAVA Beginner in need of help) Pin
bakary.konate27-Apr-13 10:32
bakary.konate27-Apr-13 10:32 
Questionhow to call webservice in java using javascript with example link Pin
Member 999857419-Apr-13 8:02
Member 999857419-Apr-13 8:02 
AnswerRe: how to call webservice in java using javascript with example link Pin
Richard MacCutchan19-Apr-13 9:13
mveRichard MacCutchan19-Apr-13 9:13 
Questionjava Pin
Tyga Von Brown16-Apr-13 9:02
Tyga Von Brown16-Apr-13 9:02 
AnswerRe: java Pin
Richard MacCutchan16-Apr-13 9:36
mveRichard MacCutchan16-Apr-13 9:36 
AnswerRe: java Pin
NotPolitcallyCorrect16-Apr-13 10:14
NotPolitcallyCorrect16-Apr-13 10:14 
AnswerRe: java Pin
Shubhashish_Mandal26-Apr-13 0:00
professionalShubhashish_Mandal26-Apr-13 0:00 
QuestionOneWay hash encryption error in different Os. Pin
saigowthami15-Apr-13 1:27
saigowthami15-Apr-13 1:27 
AnswerRe: OneWay hash encryption error in different Os. Pin
Richard MacCutchan15-Apr-13 2:18
mveRichard MacCutchan15-Apr-13 2:18 
GeneralRe: OneWay hash encryption error in different Os. Pin
saigowthami15-Apr-13 19:31
saigowthami15-Apr-13 19:31 
GeneralRe: OneWay hash encryption error in different Os. Pin
Richard MacCutchan15-Apr-13 22:00
mveRichard MacCutchan15-Apr-13 22:00 
GeneralRe: OneWay hash encryption error in different Os. Pin
saigowthami15-Apr-13 23:09
saigowthami15-Apr-13 23:09 
GeneralRe: OneWay hash encryption error in different Os. Pin
Richard MacCutchan15-Apr-13 23:21
mveRichard MacCutchan15-Apr-13 23:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.