• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Need some clarification for OOPS concepts

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have some of the doubts for OOPS concepts of Java , need more clarification about what happens in the background

1. Why cant we assign a super class object to sub class refrence ?
2. why its not necessary to have a same return type for overloaded methods and overriden methods ?
3. when (compile/run time) is it getting decided that which overladed / overriden method has to be called and why ?
4. exact diffrent between compiler and interpreter and how do they work in the background ?
5. what is Java compiler ? compiler + interpreter ? or only interpreter ? need more clarification on this ?


Please provide me the link or clarification on this above ... and also it will be great if i get alink for such kind of basic details ...
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

G Nair wrote:1. Why cant we assign a super class object to sub class refrence ?


Take the following example:
- super class Animal
- sub classes Dog and Cat
You can use a cast to force the compiler to still accept it, but then you'll get a ClassCastException.

2. why its not necessary to have a same return type for overloaded methods and overriden methods ?


Overloaded methods are completely different methods that have only one thing in common - the name. Other than that there is (syntactically) nothing in common.
Overridden methods must have the same return type, or a narrower. This is called covariant return. Look it up.

3. when (compile/run time) is it getting decided that which overladed / overriden method has to be called and why ?


For overloaded methods the compiler decides which one to use. During runtime the JVM uses the actual instance to find out from which class the method should be called. This must be done during runtime because during compile time the type simply isn't known.

4. exact diffrent between compiler and interpreter and how do they work in the background ?


I'm sure you can find an answer if you SearchFirst. Google and Wikipedia should be more than able to help you with this.

5. what is Java compiler ? compiler + interpreter ? or only interpreter ? need more clarification on this ?


The name says it all. The Java compiler is only a compiler. The JVM is an interpreter that also includes a JIT compiler. Again, Google or use our search for more info.
 
G Nair
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you so much Rob , These kind of questions have been asked for interviews wherever i go , so would like to know more about the which book from the following can help me

1.Complete Reference Java
2.Head First Java
3. SCJP book by cathy

Please let me know if you have any like for the same .
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

G Nair wrote:which book from the following can help me
1.Complete Reference Java
2.Head First Java
3. SCJP book by cathy


apart from this, there is one more *Thinking in Java* . if you want to know about interpreter more then look into the JVM specifications
 
reply
    Bookmark Topic Watch Topic
  • New Topic