Skip to content

Commit fe82077

Browse files
author
Ram swaroop
committed
constructors: question added
1 parent 6e8acc6 commit fe82077

1 file changed

Lines changed: 57 additions & 13 deletions

File tree

_posts/2015-06-30-constructors.md

Lines changed: 57 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,9 @@ public class Animal {
301301
}
302302
{% endhighlight %}
303303

304-
A. `abc`<br>
305-
B. Empty string<br>
306-
C. Won't compile<br>
304+
A. `abc`
305+
B. Empty string
306+
C. Won't compile
307307
D. Runtime error
308308

309309
__Q2.__ What is the result?
@@ -327,10 +327,10 @@ public class Bottom2 extends Top {
327327
}
328328
{% endhighlight %}
329329

330-
A. BD<br>
331-
B. DB<br>
332-
C. BDC<br>
333-
D. DBC<br>
330+
A. BD
331+
B. DB
332+
C. BDC
333+
D. DBC
334334
E. Compilation fails
335335

336336
__Q3.__ What is the result?
@@ -363,9 +363,53 @@ public class SubSubAlpha extends Alpha {
363363
}
364364
{% endhighlight %}
365365

366-
A. subsub<br>
367-
B. sub subsub<br>
368-
C. alpha subsub<br>
369-
D. alpha sub subsub<br>
370-
E. Compilation fails<br>
371-
F. An exception is thrown at runtime
366+
A. subsub
367+
B. sub subsub
368+
C. alpha subsub
369+
D. alpha sub subsub
370+
E. Compilation fails
371+
F. An exception is thrown at runtime
372+
373+
__Q4.__
374+
375+
{% highlight java linenos %}
376+
377+
class Building {
378+
Building() {
379+
System.out.print("b ");
380+
}
381+
382+
Building(String name) {
383+
384+
this();
385+
System.out.print("bn " + name);
386+
}
387+
}
388+
389+
public class House extends Building {
390+
House() {
391+
System.out.print("h ");
392+
}
393+
394+
House(String name) {
395+
this();
396+
System.out.print("hn " + name);
397+
398+
}
399+
400+
public static void main(String[] args) {
401+
new House("x ");
402+
}
403+
}
404+
{% endhighlight %}
405+
406+
What is the result?
407+
408+
A. h hn x
409+
B. hn x h
410+
C. b h hn x
411+
D. b hn x h
412+
E. bn x h hn x
413+
F. b bn x h hn x
414+
G. bn x b h hn x
415+
H. Compilation fails

0 commit comments

Comments
 (0)