• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

doubt bank dare to answer 1

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi everyone,
i took a numerous mock exams and i have listed the doubts and sums which ever i didn't understand. here is the listing. please answer them..

1. [B]Explain the output if it compiles[/B]

2.
Explain the output if it compiles..

3. can we place


4. what is the difference between an error and exception please explain with code.

5. can we place try/catch inside catch/finally block?

6. why cant we throw and assertion error?

7. is overloading of main such as

accepted in the same file?

8.

k &b says

Enables assertions in gerneral, but dissable assertions in package com.foo and any of its subpackages

but the explanation given above says " in java every package is treated as a completely distinct package that has no relationship with the packages above it"
where comes the concept of subpackage or what is a subpackage??



9.what is the diffence between ?

10. Can we implement throwable and create our own exception if yes please explain with coding..




this is first set of doubts and remaining given as next topic,
i cant understand the explanation given by them. so anyone clear my doubt with coding and explanation

thanks in advance

regards
Harinath Chakrapani
 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


1. [B]Explain the output if it compiles[/B]



Compiler Error, variable x is already defined.


2.
Explain the output if it compiles..


long can take int, so at each iteration one element from the int array
will be assigned to the n that is long. Here you are traversing the int
array a. Output 1 2 3 4 5


3. can we place



No! finally must come last. catch{} can't follow the finally block.
Although finally{} can be used individually with the try{} without catch{}


4. what is the difference between an error and exception please explain with code.



See the Throwable class, Exception and Error classes extend from the
Throwable class.
Examples of Error are StackOverflowError, ExceptionInInitializationError
and so.

Try to run an infinite loop, after some seconds you will find the former
exception. Try to place a code that throws exception in the static block,
as divide by zero, you will get the later error when you run the code.



5. can we place try/catch inside catch/finally block?


Yeah of course, why don't you try it?


6. why cant we throw and assertion error?


You can! But you should not.


7. is overloading of main such as

accepted in the same file?



It is not overloading the main() method. Only changing the return type
does not mean overloading. You will get compiler error here.


8.

9.what is the diffence between ?



Myclass.Testclass means Myclass is a package and Testclass is the class
under that.

java -ea:Myclass Testclass says, enable assertion in the Testclass package,
and launch the Testclass main() method.



10. Can we implement throwable and create our own exception if yes please explain with coding..



Yeah, you can. But often you extend Exception to create your own exception.

class MyThrowable extends Throwable {
...
code to construct the exception and return the exception in message form.
...
}

Thanks,
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Harinath Chakrapani. Please, show some effort that you have tried to solve these problems yourself. This is not a beginner's forum and you should be able to write simple programs which can help you find the solutions.

And please quote your sources - where did all these questions come from?

Posts like yours just give an impression of laziness.
 
Enthuware Software Support
Posts: 4650
51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good effort, Chandra

Harinath, as Barry suggested, if you try coding these and see them in action, you will learn it a lot better
 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Harinath,

I see couple of posts more besides this, where your question asking pattern
is same. It seems they are frequently asked interview questions, and you want
frequent answers as well.

I personally feel bad when I see any post with 0 reply, so attempted to reply
this lengthy post My experience says, in JavaRanch, no post stay
deserted/non-replied for long.

Thanks,
[ June 24, 2007: Message edited by: Chandra Bhatt ]
 
this is supposed to be a surprise, but it smells like a tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic