Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


11. static class A {
12. void process() throws Exception { throw new Exception();
}
13. }
14. static class B extends A {
15. void process() { System.out.println(”B”); }
16. }
17. public static void main(String[] args) {
18. new B().process();
19. }
What is the result?
1 B
2 The code runs with no output.
3 Compilation fails because of an error in
line 12.
4 Compilation fails because of an error in
line 15.

Answers were Sorted based on User's Feedback



11. static class A { 12. void process() throws Exception { throw new Exception(); } 13. } 14. s..

Answer / neil

B

Is This Answer Correct ?    15 Yes 4 No

11. static class A { 12. void process() throws Exception { throw new Exception(); } 13. } 14. s..

Answer / r.jainrocks@gmail.com

Compilation fails

static keyword not allowed here
at line 11 and 14

Is This Answer Correct ?    9 Yes 3 No

11. static class A { 12. void process() throws Exception { throw new Exception(); } 13. } 14. s..

Answer / vasanth g

Here we are directly process method of class b.
so ans B that is 1st option....
consider this

static classA {
void process() throws Exception { throw new Exception(); }
}
static class B extends A {
void process() { System.out.println(&#65533;B &#65533;); }
}
public static void main(String[] args) {
A a=new B();
a.process();
}

in this program compilation fails at a.process
because compiler doen't know that reference a point on class
B where there's no exception. a is of A type and A's method
throws exception that isn't handled .a.process() enclosed in
try catch block.

Is This Answer Correct ?    4 Yes 0 No

11. static class A { 12. void process() throws Exception { throw new Exception(); } 13. } 14. s..

Answer / manikandan [ gtec,vellore ]

Answer is 1)B because we directly calling a process method
in class B

Is This Answer Correct ?    5 Yes 2 No

11. static class A { 12. void process() throws Exception { throw new Exception(); } 13. } 14. s..

Answer / bhanu

hi,

Keep the whole code in a class
Ex:
class Sample
{
.....
..... //the above code
.....
.....
}

Now it will not give any error while compilation.
It is the concept of static nested classed
Thank you

Is This Answer Correct ?    1 Yes 0 No

11. static class A { 12. void process() throws Exception { throw new Exception(); } 13. } 14. s..

Answer / souvik

The answer will be first option B since the object created is of B type and it is calling directly the process method in B class

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Core Java Interview Questions

Is oracle charging for java?

0 Answers  


What is vector capacity in java?

0 Answers  


What is the difference between a break statement and a continue statement?

0 Answers  


What is Map interface?

3 Answers   Wipro,


Is it correct to say that due to garbage collection feature in java, a java program never goes out of memory?

0 Answers  


What is an error in java?

0 Answers  


Explain the difference between abstract class and interface in java?

0 Answers  


What do you understand by an io stream?

0 Answers  


How to create packages in java?

0 Answers  


Why java Don't Support Multiple interitence

8 Answers   ABC, Exilant, IBM,


Which is a valid identifier?

0 Answers  


can we create object for static class in java

14 Answers   IAP Company, IBM, Marlabs, mPortal, TCS,


Categories