Вопрос из сертификации Java SE8 Pro 1z0-809
Подробнее
Which statements concerning the following code are true? class A { public A() {> // A1 public A(String s) { thisO; System.out.println("A :"+s); > // A2 > class 3 extends A { public int B(String s) { System.out.println("B :”+s); return 0; > // B1 > class C extends B { private C(){ super(); > // Cl public C(String s){ this(); System.out.println(''C :"+s); > // C2 public C(int i){> // C3 >____________________________________________________________________________________________________________________________________________________________________________________________________________________________ Answered Correctly You had to select 4 option(s) ✓ One of the constructors of each class is called as a result of constructing an object of class C. r------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------1 ¡To create any object one and only one constructor of that class and each of the super classes is called (not counting the constructors that are invoked by another constructor using the this(... ) statement).! i------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------j ✓ Constructor at //A2 will never be called in creation of an object of class C r------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ¡Observe that class B has no constructor defined. Therefore, the compile will automatically provide a default no-argument constructor to B. This default constructor will call the no-argument constructor of A. ¡Thus, the constructor at //A2 will never get invoked during the creation of on object of class C. L.----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ✓ Class C can be instantiated only in two ways by users of this class. r......................................................................................................................................................... ¡Since one of the three constructor is private, users of this class (i.e. classes other than class C) can use only the two public constructors to create an object of this class.! 1.. ...............................................................................................................................................................................-j s/ // B1 will never be called in creation of objects of classes A, B, or C r--------------------------------------------------------------------------------------i ¡Because i!B1 is not a constructor. Note that it is returning an int, so it is a method.! 1.. .............................................................................................j
geek,Прикольные гаджеты. Научный, инженерный и айтишный юмор,it-юмор,it,java,экзамен,сертификат
Еще на тему
Сидишь и думаешь позволит ли язык такую хрень или стандарт опять сменился.