We can access a static property of a class by writing className.propertyName, but if the property (method/variable) is private then is it possible to access that property? For example, This will print A.a = 50 But if I change static int a = 50; to private static int a = 50; then can I access that variable any how? Answer
Tag: oop
How to represent bi-directional associations in UML?
After reading the question “In UML class diagram can composition be bidirectional?”, I’m wondering how concrete examples of bi-directional shared/composite aggregation will look on a UML diagram. Specifically, I’m interested how arrow-heads and multiplicity are used to distinguish between the following cases: 1) Uni-directional shared aggregation (aggregation) 2) Bi-directional shared aggregation (aggregation) 3) Uni-directional composite aggregation (composition) 4) Bi-directional composite
How would you convert this method into a ternary expression?
I want to convert those if-statements into a ternary operator expression, but I’ve been struggling since I haven’t had the need to use them that much. The code essentially replaces the characters ‘1’ with ‘i’, removes characters that are not letters, and also removes upper-case letters by enqueuing elements that don’t meet those conditions. Edit: thanks for your comments, code
How to inher variables values from one page to another in java?
I’m new to java and I’m stuck with this. I have one BasePage class that contains a “global” List and an int value like this; Moreover, I’ve two classes that extend that page; And other: Then, when I access “stringList” and “number” after calling that who classes, the values are not “stacked” in BasPage. Is there a way to achieve
Making method generic and attributes
I am using quite a similar method for 4, 5 screens basically to do same thing on List of different objects. Now I extracted that method to reuse it and make it generic. Now while making a list generic I face the issue with attributes. It’s attributes are no longer accessible when made generic. How to overcome this issue. Please
Generic class that implements a particular interface
So lets take this example that I have a class A and class B both A and B are implementing a specific interface letters. Now I need to make a specific function in another class wherein I need to pass either A class object or B class object and similarly do some operation on these objects and return either A
How can I prevent an overwrite and add to exisiting array (Java)
My project mostly works as intended, save for the fact that my methods will overwrite the initial entry and not add the new entry to the array. For instance if I input 2 entries via option 1, and then attempt to add another (single) entry via option 2, index 0 is overwritten by the new entry. I’ve tried making the
Are API calls in a mapper considered a bad practice?
It’s quite common to use DTOs as API models. Often you need to map those DTOs to other models afterwards. I will keep it really simple with following example: So in the above case RequestDto is the model that is used in the API and SomeModel is the model that is used internally by the server for the business logic.
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 for inheritance, however, the fact that the inputs and outputs are different and are related to two lambdas, make me wonder if they should remain
How do I create a constructor for a class that is inheriting from an abstract class with generics?
My university professor shared this class with us (it’s essentially a generic parser using Gson): I created a class that inherits from it so I can read a Business from a file: Intellij automatically generated a constructor for it, but I don’t understand it. Why does the constructor has a class as a parameter, do I have to pass an