Local Objects

Local Objects

Objects basically also behave differently when It is declared within a method rather than as instance

When its with instance variable object references we can got that time its with leaving an object reference uninitialized,and also that time when we reach the code its not null.

But here most imp thing is a null reference is not the same as an uninitialized reference. we have a example where compiler complain about the following code :

import java.util.Date;
public class TimeTravel {
public static void main(String [] args) {
Date date;
if (date == null)
System.out.println(\"date is null\");

When it is complile we got these type of errors :
%javac TimeTravel.java
TimeTravel.java:5: Variable date may not have been initialized.
If (date == null)
1 error

Date:2024-02-09 00:00:00

Post Your Answers

User Email:

User Name:

Related SCJP1.5 chap1 Links

SCJP1.5 chap1 interview questions and answers for experienced and fresher