Composition or Inheritance for classes with almost similar implementations but different input and outputs for methods?

I have the following classes, which have quite similar method implementations. Only the classes’ method inputs and outputs seem to be of different types. When I put it like this, it sounds like a case …

Java OOP; creating array of objects

I’d like to create an array of objects where 3 objects are from one class, and a 4th is from second class. In the first class I did the following: public class Pupil { public int n= 0; …

java.lang.ClassCastException exception using ObjectInputStream, when sending a class as an object

https://github.com/IshayKom/RCProject Classes As Shown in the eclipse package manager (I don’t really deal with github so I don’t know how to upload classes correctly) I got an error running my …

How to create objects for parameterized constructors in Java, when we have two classes with the same attributes?

I have class Student, that has first name, last name and age, and a method to print the name and the age of the student. public class Student { private String firstName; private String …

Can I pass a field of a class to a constructor or a method?

I have the following class: public abstract class Map { protected PriorityQueue openNodes; } My implementation currently work like this: public Map() { PriorityQueue<Node&…

How to use class type of method parameter?

I have the following classes: Foo1 extends Bar and Foo2 extends Bar I would like to pass the type of either Foo1, or Foo2 in my method to create either a Foo1, or a Foo2, like this: public Bar …

Java – violation of Liskov substitution principle?

I have the following code: interface Ops{ void remove(); } interface BeforeRemove{ void doBeforeRemove(); } class A implements Ops{ @Override public void remove() { System….

How would I make a new fraction if a fraction cannot be simplified?

So I’m writing an assignment for my OOP class that asks the user for a number of fractions, then randomly generates that number of fractions. Part of the assignment states that if one of the fractions …

is there a preferable relationship between classes? Why? [closed]

is there really a preferable relationship between classes ? or it depends on the software we have ? I know that we have is-a and has-a relationships in classes relations but, is there a one relation …

How to call the method of the subclass using method of Parent class?

I have a Shape method that has two arguments first is the width and the second is the height. I have two subclasses, one is the rectangle and another is triangle. I want to call the area() the method …