دستگرمی
دستگرمی پانزدهم

اینبار یک دستگرمی با چاشنی وراثت داریم! این دستگرمی رو جناب آقای ابوالفضل صادقی تهیه کردند.
با توجه به اینکه متد printf مانند printf در سی عمل میکند و به جای s% رشته و به جای d% مقدار int را جایگزین میکند، خروجی کد زیر را از بین گزینههای زیر انتخاب کنید.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | public class Main { public static void main(String[] args) { new Child(); System.out.println("STATIC FIELD AGE IS " + Child.age); } } class Parent { public static int age = 48; public final String name = "ahmed"; public String family = "ahmedi"; private String phone = "+981212121212"; public Parent() { System.out.println("=======running on========>" + this.getClass()); System.out.printf("constructor$name:%s\n", name); logName(); System.out.printf("constructor$family:%s\n", family); logFamily(); System.out.printf("constructor$age:%d\n", age); logAge(); System.out.printf("constructor$phone:%s\n", phone); logPhone(); } public void logName() { System.out.printf("name is %s\n",this.name); } public void logFamily() { System.out.printf("family is %s\n", this.family); } public void logAge() { System.out.printf("age is %d\n", this.age); } private void logPhone() { System.out.printf("phone is %s\n", this.phone); } } class Child extends Parent { public String name = "jafari"; public Child() { System.out.println("=======parent is=========>" + super.getClass()); System.out.println("=======running on========>" + this.getClass()); System.out.printf("constructor$name:%s\n", name); logName(); System.out.printf("constructor$family:%s\n", family); logFamily(); System.out.printf("constructor$age:%d\n", age); logAge(); } @Override public void logFamily() { System.out.println("family is akbarAbadi"); } } |
گزینهها
گزینه ۱
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | =======running on========>class Child constructor$name:ahmed name is ahmed constructor$family:ahmedi family is akbarAbadi constructor$age:48 age is 48 constructor$phone:+981212121212 phone is +981212121212 =======parent is=========>class Child =======running on========>class Child constructor$name:jafari name is ahmed constructor$family:ahmedi family is akbarAbadi constructor$age:48 age is 48 STATIC FIELD AGE IS 48 |
گزینه ۲
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | =======running on========>class Parent constructor$name:ahmed name is ahmed constructor$family:ahmedi family is ahmedi constructor$age:48 age is 48 constructor$phone:+981212121212 phone is +981212121212 =======parent is=========>class Parent =======running on========>class Child constructor$name:jafari name is jafari constructor$family:ahmedi family is akbarAbadi constructor$age:48 age is 48 STATIC FIELD AGE IS 48 |
گزینه ۳
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | =======running on========>class Child constructor$name:jafari name is jafari constructor$family:ahmedi family is ahmedi constructor$age:48 age is 48 constructor$phone:+981212121212 phone is +981212121212 =======parent is=========>class Parent =======running on========>class Child constructor$name:jafari name is jafari constructor$family:ahmedi family is akbarAbadi constructor$age:48 age is 48 STATIC FIELD AGE IS 0 |
گزینه ۴
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | =======running on========>class Parent constructor$name:jafari name is jafari constructor$family:ahmedi family is ahmedi constructor$age:48 age is 48 constructor$phone:+981212121212 phone is +981212121212 =======parent is=========>class Parent =======running on========>class Child constructor$name:jafari name is jafari constructor$family:ahmedi family is akbarAbadi constructor$age:48 age is 48 STATIC FIELD AGE IS 0 |
طراح عزیز: جناب آقای ابوالفضل صادقی
.
.
.
.
با ما همراه باشید
آدرس کانال تلگرام: JavaCupIR@
آدرس اکانت توییتر: JavaCupIR@
آدرس صفحه اینستاگرام: javacup.ir
صفحه ویرگول: javcup
آدرس گروه لینکدین: Iranian Java Developers