Sponsored Links

Interview Questions



INTERVIEW QUESTIONS J2EE JAVA DETAILS

Question: Solve it...
public class test {

public static void main(String[] args)
{
int i=5;
i=i++;
System.out.println("result::"+i);
}
}

Answer: i=i++

can be taken up as i=(i=i+1)

here the value of i=5 initially .. then which one is it.. i=5 or i++ in the next line ..?

Category Java Interview Questions & Answers - Exam Mode / Learning Mode
Rating (0.2) By 9749 users
Added on 8/14/2011
Views 69996
Rate it!

Question: Solve it...
public class test {

public static void main(String[] args)
{
int i=5;
i=i++;
System.out.println("result::"+i);
}
}



Answer:

i=i++

can be taken up as i=(i=i+1)

here the value of i=5 initially .. then which one is it.. i=5 or i++ in the next line ..?
Source: CoolInterview.com


i m not satisfied with above answer i think it shud be like or we can take this :

public class Test {
public static void main(String p[]) {

for(int i=5; i<20; i++)
System.out.println("result" + i);
}
}
plz tell me if i am wrong
Source: CoolInterview.com

Answered by: sarika | Date: | Contact sarika Contact sarika

int i=5;
first it stores value 5.
i=i++;
when this statement is executed first it copies value 5 in i.again it increments value assigning value to the same variable i.so it will becomes 6.
if we r doing like this
int i=5;
int a;
a=i++;
System.out.println(a);
it prints 5;
System.out.println(i);
it prints 6; Source: CoolInterview.com

Answered by: Hazi Pasha.MD | Date: | Contact Hazi Pasha.MD Contact Hazi Pasha.MD

here the increment is the post increment so the value of the i is 5 Source: CoolInterview.com

Answered by: phani | Date: | Contact phani Contact phani

In my point of view the answer is 5 because whenever you increment a value with ++ operator it doesnot get display in the next line we have to declare one more variable for it and then show it there in this program the answer is 5 we can pront the i++ value as
public class test {

public static void main(String[] args)
{
int i=5;
i=i+1;
System.out.println("result::"+i);
}
}
In the above program it will print six which shows the difference that in the ++ operator and +1
Source: CoolInterview.com

Answered by: Rahul Sehgal | Date: | Contact Rahul Sehgal Contact Rahul Sehgal

answer is 5.
the answer is 6 if i=++i. Source: CoolInterview.com

Answered by: rajarajeswari.k | Date: | Contact rajarajeswari.k Contact rajarajeswari.k

The answer is 5.

To see what the answer is the best way is to type this snippet into a file,compile it and run it.
You'll get the answer 5.

It is how post-increment works.

Use the current value of i(that is to assign itself to i) then increment it. Source: CoolInterview.com

Answered by: Seetharam | Date: 1/8/2008 | Contact Seetharam Contact Seetharam

The answer will be 6 because i++ increase the value of i by 1 so i will store the value 5+1 i.e. 6.
Source: CoolInterview.com

Answered by: anil agnihotri | Date: 2/1/2008 | Contact anil agnihotri Contact anil agnihotri

The answer is 6. I will give u the valid reason. Because i++ is a Right to Left associatve, the evaluation starts from right. So, the increment of i variable takes place first and then assigned to i. Source: CoolInterview.com

Answered by: Rajshekhar | Date: 9/21/2008 | Contact Rajshekhar Contact Rajshekhar

The answer is 5.

int i=5;//initial value of i is 5
i=i++;//No change, if ++i then 5 get incremented.
Source: CoolInterview.com

Answered by: Jinu | Date: 1/1/2010 | Contact Jinu Contact Jinu

The answer is 5.
int i=5;
i=i++;
here i value is 5 so first time it will assign then increment.
Source: CoolInterview.com

Answered by: anurag | Date: 5/23/2010 | Contact anurag Contact anurag

here answer is 5
first thing is that initially its value was i=5
after post increment if it was asked to print value of i then it would be i=5;
because first value will print and then new value will store in i.
Source: CoolInterview.com

Answered by: abhishek mishra | Date: 8/10/2010 | Contact abhishek mishra Contact abhishek mishra


If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
  • There should not be any Spelling Mistakes.
  • There should not be any Gramatical Errors.
  • Answers must not contain any bad words.
  • Answers should not be the repeat of same answer, already approved.
  • Answer should be complete in itself.
Name :*
Email Id :*
Answer :*
Verification Code Code Image - Please contact webmaster if you have problems seeing this image code Not readable? Load New Code
Process Verification Enter the above shown code: *
Inform me about updated answers to this question

Related Questions
View Answer
What is garbage collection?Can it be forced?

View Answer
What is difference between & and && in java

View Answer
send me some interview questions on Stringhandling concept
View Answer
Is is true that JAVA is not 100% object oriented language ?

View Answer
Difference b/w synchronized Method and synchronized statement in case of whole body of method cover by synchronized statement.

View Answer
How do you know that where to use abstract class or interface?

View Answer
How System.out.println() works?

View Answer
can the main() method be overloaded? or overrided? and what happens when we do so?

View Answer
What is the use of keyword transient?

View Answer
What is Log4j in java

View Answer
Why we can not override static method?

View Answer
How to create the object to the anonomous class

View Answer
What is the difference between array list and linked list. in which situations we are use them? which is best one?

View Answer
Can i expand an interface?

View Answer
what happens if we execute the program?
class Return{
int display(){
try{
return 1;
}
finally{
return 2;
}
}
public static void main(String args[]){
Return r=new Return();
r.display();
}
}

View Answer
If interface has got four methods,and I like to implement only two methods, how this could be achieved?

View Answer
Does JVM maintain a cache by itself? Does the JVM allocate objects in heap? Is this the OS heap or the heap maintained by the JVM? Why

View Answer
What are the primitive types in Java?

View Answer
How would you implement a thread pool

View Answer
How do you declare constant values in java?

View Answer

Please Note: We keep on updating better answers to this site. In case you are looking for Jobs, Pls Click Here Vyoms.com - Best Freshers & Experienced Jobs Website.

View All Java Interview Questions & Answers - Exam Mode / Learning Mode



User Options
India News Network

Latest 20 Questions
Payment of time- barred debt is: (a) Valid (b) Void (c) Illegal (d) Voidable
Consideration is defined in the Indian Contract Act,1872 in: (a) Section 2(f) (b) Section 2(e) (c) Section 2(g) (d) Section 2(d)
Which of the following is not an exception to the rule, "No consideration, No contract": (a) Natural love and affection (b) Compensation for involuntary services (c) Completed gift (d) Agency
Consideration must move at the desire of: (a) The promisor (b) The promisee (c) The promisor or any other party (d) Both the promisor and the promisee
An offer which is open for acceptance over a period of time is: (a) Cross Offer (b) Counter Offer (c) Standing Offer (d) Implied Offer
Specific offer can be communicated to__________ (a) All the parties of contract (b) General public in universe (c) Specific person (d) None of the above
_________ amounts to rejection of the original offer. (a) Cross offer (b) Special offer (c) Standing offer (d) Counter offer
A advertises to sell his old car by advertising in a newspaper. This offer is caleed: (a) General Offer (b) Special Offer (c) Continuing Offer (d) None of the above
In case a counter offer is made, the original offer stands: (a) Rejected (b) Accepted automatically (c) Accepted subject to certain modifications and variations (d) None of the above
In case of unenforceable contract having some technical defect, parties (a) Can sue upon it (b) Cannot sue upon it (c) Should consider it to be illegal (d) None of the above
If entire specified goods is perished before entering into contract of sale, the contract is (a) Valid (b) Void (c) Voidable (d) Cancelled
______________ contracts are also caled contracts with executed consideration. (a) Unilateral (b) Completed (c) Bilateral (d) Executory
A offers B to supply books @ Rs 100 each but B accepts the same with condition of 10% discount. This is a case of (a) Counter Offer (b) Cross Offer (c) Specific Offer (d) General Offer
_____________ is a game of chance. (a) Conditional Contract (b) Contingent Contract (c) Wagering Contract (d) Quasi Contract
There is no binding contract in case of _______ as one's offer cannot be constructed as acceptance (a) Cross Offer (b) Standing Offer (c) Counter Offer (d) Special Offer
An offer is made with an intention to have negotiation from other party. This type of offer is: (a) Invitation to offer (b) Valid offer (c) Voidable (d) None of the above
When an offer is made to the world at large, it is ____________ offer. (a) Counter (b) Special (c) General (d) None of the above
Implied contract even if not in writing or express words is perfectly _______________ if all the conditions are satisfied:- (a) Void (b) Voidable (c) Valid (d) Illegal
A specific offer can be accepted by ___________. (a) Any person (b) Any friend to offeror (c) The person to whom it is made (d) Any friend of offeree
An agreement toput a fire on a person's car is a ______: (a) Legal (b) Voidable (c) Valid (d) Illegal



Fresher Jobs | Experienced Jobs | Government Jobs | Walkin Jobs | Company Profiles | Interview Questions | Placement Papers | Companies In India | Consultants In India | Colleges In India | Exams In India | Latest Results | Notifications In India | Call Centers In India | Training Institutes In India | Job Communities In India | Courses In India | Jobs by Keyskills | Jobs by Functional Areas

Testing Articles | Testing Books | Testing Certifications | Testing FAQs | Testing Downloads | Testing Interview Questions | Testing Jobs | Testing Training Institutes

Gate Articles | Gate Books | Gate Colleges | Gate Downloads | Gate Faqs | Gate Jobs | Gate News | Gate Sample Papers | Gate Training Institutes

MBA Articles | MBA Books | MBA Case Studies | MBA Business Schools | MBA Current Affairs | MBA Downloads | MBA Events | MBA Notifications | MBA FAQs | MBA Jobs
MBA Job Consultants | MBA News | MBA Results | MBA Courses | MBA Sample Papers | MBA Interview Questions | MBA Training Institutes

GRE Articles | GRE Books | GRE Colleges | GRE Downloads | GRE Events | GRE FAQs | GRE News | GRE Training Institutes | GRE Sample Papers

IAS Articles | IAS Books | IAS Current Affairs | IAS Downloads | IAS Events | IAS FAQs | IAS News | IAS Notifications | IAS UPSC Jobs | IAS Previous Question Papers
IAS Results | IAS Sample Papers | IAS Interview Questions | IAS Training Institutes | IAS Toppers Interview

SAP Articles | SAP Books | SAP Certifications | SAP Companies | SAP Study Materials | SAP Events | SAP FAQs | SAP Jobs | SAP Job Consultants
SAP Links | SAP News | SAP Sample Papers | SAP Interview Questions | SAP Training Institutes |




Copyright ©2003-2025 CoolInterview.com, All Rights Reserved.
Privacy Policy | Terms and Conditions