Rituka Jaiswal

Greenhorn
+ Follow
since Sep 27, 2011
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Rituka Jaiswal

Can anyone explain in more detail, still unable to understand fully..
Why false was printed on the console?


It says it will print false on the standard output.
01. import Outer.Inner.InnerMost;
02. import Outer.*;
03.
04. class Outer {
05. int i;
06. class Inner {
07. Inner() {i++;}
08.
09. class InnerMost extends Inner {
10. InnerMost() {i++; System.out.println(i);}
11. }
12. }
13. interface InnerInterface {
14. void doSomething();
15. }
16. }
17.
18. public class Test implements InnerInterface{
19.
20. public void doSomething() {
21. System.out.println("done");
22. }
23.
24. public static void main(String[] args) {
25. Inner im = new Outer().new Inner().new InnerMost();
26. }
27. }


The output is 3, Why is it not 2??
01. class BadObjectException extends Exception {}
02. class BadIndexException extends IndexOutOfBoundsException {}
03.
04. public class Test {
05.
06. public void doSomething() {}
07.
08. public void aMethod() {
09. try {
10. doSomething();
11. }catch(BadIndexException be) {
12. System.out.println("BadIndexException");
13. throw new BadIndexException(){};
14. }
15. }
16.
17. public void anotherMethod() throws BadObjectException{
18. try {
19. doSomething();
20. }catch(BadObjectException be) {
21. System.out.println("BadObjectException");
22. }
23. }
24.
25. public static void main(String[] args) throws BadObjectException{
26. Test t = new Test();
27. t.aMethod();
28. t.anotherMethod();
29. }
30. }

the output is that metnod anotherMethod() would not compile.