mjstx
mjstx
JCHJava Community | Help. Code. Learn.
Created by mjstx on 1/2/2025 in #java-help
Java GUI not loading images/ImageIcons help
No description
9 replies
JCHJava Community | Help. Code. Learn.
Created by mjstx on 12/10/2024 in #java-help
java basics help
For this example:
public class Animal {
public void makeSound (){
System.out.println("animal sounds");
}
}

public class Cat extends Animal{
public void makeSound (){
System.out.println("meow");
}
}

public class Dog extends Animal{
public void makeSound (){
System.out.println("woof");
}
}

public class test {
Animal dog = new Dog();
Animal cat = new Cat();
}
public class Animal {
public void makeSound (){
System.out.println("animal sounds");
}
}

public class Cat extends Animal{
public void makeSound (){
System.out.println("meow");
}
}

public class Dog extends Animal{
public void makeSound (){
System.out.println("woof");
}
}

public class test {
Animal dog = new Dog();
Animal cat = new Cat();
}
I dont understand why we do this: Animal dog = new Dog(); Animal cat = new Cat(); Why not just do something like, Dog dog = new Dog();, Cat cat = new Cat(); Also why CAN we do this and why doesnt it throw an error, because ive seen it happen that the left hand side of the initialization was sometimes an interface? One thing that I found online was thit helps with abstraction, like for the method below. But why does it even make a difference at all, since Dog dog = new Dog(); is still an Animal so the method should it accept it too right? public void handleSound (Animal animal) { animal.makeSound(); }
39 replies
JCHJava Community | Help. Code. Learn.
Created by mjstx on 6/5/2023 in #java-help
Creating a Java Unit test vectoraddition
No description
17 replies
JCHJava Community | Help. Code. Learn.
Created by mjstx on 6/4/2023 in #java-help
Junit test calling upon variable from a different class's method
No description
19 replies
JCHJava Community | Help. Code. Learn.
Created by mjstx on 6/4/2023 in #java-help
JUnit Test confusion
No description
71 replies