سلام. انگار از دوستان کسی تمایل به ترجمه این متن را نداشت. این بار این متن را با ترجمه خودم قرار می دهم. ترجمه ای که اصلاً به دل خودم منطقاً نمی نشیند:
کد:
In this example, Coffee's constructor explicitly invokes Liquid's constructor with a
super() statement. Because class Liquid explicitly declares a constructor, the Java
compiler won't generate a default constructor. Moreover, because Liquid doesn't
explicitly declare a no-arg constructor, class Liquid won't have a no-arg constructor at all.
For this reason, had Coffee's constructor not started with an explicit super() invocation,
class Coffee would not have compiled. (Given this declaration of class Liquid, a simple
new Liquid() statement would not compile either. You must invoke the constructor that is
available to you, as in: new Liquid(25, 50.0).) If a subclass's direct superclass does not
offer a no-arg constructor, every constructor in that subclass must begin with either an
explicit super() or this()invocation.
در این مثال، سازنده کلاس Coffee به صورت صریح سازنده کلاس Liquid را به وسیله super() فراخوانی میکند. به دلیل اینکه کلاس Liquid، یک سازنده را صریحاً اعلان کرده است کامپایلر جاوا از سازنده پیشفرض استفاده نخواهد کرد. علاوه بر این، به دلیل اینکه کلاس Liquid صریحاً یک سازنده بدون آرگومان را اعلان نکرده است، هرگز یک سازنده بدون آرگومان نخواهد داشت. به همین خاطر، سازنده کلاس Coffee با احضار صریح super() آغاز نشده بود.(شما باید سازندهای را احضار کنید که در دسترس شماست. مثلاً در این برنامه: new Liquid(25, 50.0)) اگر یک زیر کلاس مستقیم کلاس بالاتر، سازنده بدون آرگومانی را ارائه نکرده باشد، هر سازندهای در آن زیرکلاس باید با احضار this() یا super() آغاز شود.