简体   繁体   English

如何使用默认访问修饰符创建构造函数是参数化构造函数的类的对象

[英]How to create the object of class where constructor is parameterized constructor using default access modifier

I am working enhancement project.我正在工作增强项目。
Here they created some classes using parameterized constructor using default access modifier.在这里,他们使用default访问修饰符使用参数化构造函数创建了一些类。 I want to create those classes object and use the methods for call business functionalities.我想创建这些类对象并使用调用业务功能的方法。 packages are different.包不一样。

public class CheckAmount {

    private double balance;

    CheckAmount(double balance){
        this.balance = balance;
    }
    .....
}

so how to create the object of classes.那么如何创建类的对象。 Please provide different approches.. if possible.如果可能,请提供不同的方法。 Thanks谢谢

Default access means that access is allowed within same package.默认访问意味着在同一包内允许访问。 So you need the public modifier.所以你需要public修饰符。 Another possibility is to introduce an indirection like a factory and dependency injection, but this is more advanced.另一种可能性是引入像工厂和依赖注入这样的间接方式,但这是更高级的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何仅使用参数化构造函数为类创建对象? - how to create object for a class with only parameterized constructor? Java构造函数的默认访问修饰符 - Default access modifier for a Java constructor 如何在使用 class 参数化的 java 中创建构造函数? - How to create constructor in java parameterized with class? 调用类的参数化/默认构造函数? - Invoking parameterized/default constructor of a class? 如何让参数化构造函数链中的派生类访问使用派生构造函数初始化的基类的字段 - How to let a derived class in a parameterized constructor chain access fields of the base class that are initialized using the derived constructor 抽象类构造函数访问修饰符 - Abstract class constructor access modifier 如何从默认构造函数调用参数化构造函数? - how to call parameterized constructor from default constructor? 如何从另一个类中的public类型的参数化构造函数中调用默认类型的参数化构造函数? - How can I call parameterized constructor of default type from a parameterized constructor of type public which is in another class? 如何在没有默认构造函数的情况下创建类 - How to create class with no default constructor java中默认构造函数的访问修饰符是什么? - What's the access modifier of the default constructor in java?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM