I am learning java and came upon a small problem, my copy() method will not work. I work based on a UML diagram and I am pretty sure that I’m doing everything correctly. Here is the code: Constructor: copy() method: The error flashes at the parantheses FileName() it says: ‘FileName(java.lang.String, java.lang.String)’ in ‘Exam_Practice_4.FileName’ cannot be applied to ‘()’ Here is
Tag: constructor
How can I accept an argument list in a constructor and add it to a collection in Java?
I’m trying to make a constructor that would accept any number of variables of class “Item” as a variable argument list and add them to appropriate collection. What would be the best way to …
How can I make my program run the validation code in my sub-class rather than the parent class?
As the title suggests, I was wondering if there was a way to make my program execute the validation code in the constructor of my sub-class, instead of the validation code in the constructor in my parent class? Here is a very basic example: Here I have the constructor of my Teacher class, which throws an exception if age <
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 …
Why this code convert value to double instead to float?
I got a question. Why this code prints YYZ10.0 instead of printing XXZ10.0? The first constructor is A(int), then inside statement it returns false, so 9+1f should jump into A(float) constructor but instead it is going to A(double). Answer If there are multiple overloads of a method, Java picks which one to call at compile time, not at run time.
Java Problem: Calculations in one subclass’ constructor affecting fields of another subclass’ instance
I have two abstract classes i.e. Medicine and Prescription. All code can be found at https://codeshare.io/aVAdr3 These two classes have subclasses, the class hierarchy diagram is as follows: and… …
Why any initialization or even print inside the constructor with @Tolerate lombok cannot be reached?
what is the problem with the constructor with @Tolerate of lombok, and why it cannot be reached? and how can I fix it? I wanna initialize a map by setting some default keys and values inside the …
super.a = b instead of super(b)
I’m learning the super keyword and accidentally get this, here’s an example : public class A { double a; public A (double a) { this.a = a; } } public class B …
Spring boot error in Application.java package
hello I just created a project in spring boot initializer but when I import the project in sts I have a set of errors that I do not understand package com.example.filter.influenceur.influenceur; …
multiple constructors for final fields in java
I have some final fields in the class like class A { private final boolean a; private final boolean b; public A(boolean a){ this.a = a; } public A(boolean a, boolean b){ this.a = a; …