Click here to Skip to main content
15,885,537 members
Home / Discussions / Java
   

Java

 
Questionstruts Pin
Trupti00121-Apr-13 21:49
Trupti00121-Apr-13 21:49 
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 
I am a beginner in Java Programming and I just started programming as a hobby. I am in need of help in my Polymorphism program. How do I create an application that has an array of some size, say 5. The array should be defined of the superclass type.

Then create 5 objects where each class is represented at least once. Store the objects created into the array elements.

Finally, have the application go to each element of the array and call the display method. I should find that the display method automatically called is the one defined in the object stored in the element.

I already have a superclass which is animal and two subclasses dog and cat and a polymorphism application mainclass

Polymorphism Application: MainClass

Java
public class MainClass {
 
    public static void main(String [] args)
	{
		Animal a = new Animal();
		a.displayName("Generic Animal");
 
		Cat c = new Cat();
		c.displayName("Fluffy");
 
		Animal dog = new Dog();
		dog.displayName("Scooby-Doo"); // Polymorphic method call -- Dog IS-A Animal
 
		Animal cat = new Cat();
		cat.displayName("Mittens");   // Polymorphic method call -- Cat IS-A Animal
	}
}


Superclass (Animal):

Java
public class Animal
{
    public void displayName(String name)
    {
        System.out.println("My name is " + name);
    }
}


Subclass (Cat):

Java
public class Cat extends Animal
{
    public void displayName(String name)
    {
        System.out.println("My name is " + name + " and I like to drink milk.");
    }
}


Subclass (Dog):

Java
public class Dog extends Animal
{
    public void displayName(String name)
    {
        System.out.println("My name is " + name + " and I like to eat Scooby Snacks!");
    }
}

GeneralRe: Polymorphism Java Programming Help Pin
Richard MacCutchan21-Apr-13 0:36
mveRichard MacCutchan21-Apr-13 0:36 
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 

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.