• Post Reply Bookmark Topic Watch Topic
  • New Topic

Compiletime vs. Runtime  RSS feed

 
janki tangeda
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can anyone pls tell what type of checks are done in java at compile time?I mean what kind of errors are detected at compile time?And what type of errors are taken care of at runtime?
What do we use exceptions and Assertions for?
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to Java In General (Beginner)...
 
Satish Kumar
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At compile time , references are checked , but at run time actuall objects are checked .

here is an example .

class A
{
A()
{ }
}
class B extends A
{
}
class C extends A
{
}

class D
{
public static void main(String[] arg)
{
A a = new C();
B b = ( B ) a ;
}
in this at run time th reference are only checked , since a is typecasted , shows no error at compile time , but at run time u r objects are created , and C's object is getting assigned to B's reference , hence fails at run time .

As a simple rule , at compile time th reference are checked , actual object are created at run time .
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!