Java Tricky Program 4 - increment decrement operator

preview_player
Показать описание
Java increment and decrement operators can be used to increase or decrease the value by 1. They can be applied before the int variable or after that, called prefixed and postfixed.
In an expression prefixed operator is applied before the value is used in expression and in case of postfix, it's applied after the value is put in expression.
We will also learn the code flow when we have static and non-static blocks in super class and sub class and we are creating an instance of subclass.
Рекомендации по теме
Комментарии
Автор

loved it, whole series is simply super explanation.

mkkamle
Автор

Keep upthe nice work... i loved ur channel

asolmanuh
Автор

Hi, one doubt regarding i= --i - i--;
So, we can see pre decrement happened but why not post decrement happened, as I was thinking like i=(1-1) and post decrement so output will be i=-1

sushilmadankar
Автор

I don't understand why on the third step you wouldn't use a negative one because on the second step there is a post decrementation that would make 0 to -1.

charleybucketcdp
Автор

Dear Respected Sir,

Please clear my doubts on Increment/Decrement Operators in JAVA...Sir, Please Observed This code Below..

class Test
{
public static void main(String[] args)
{
int a = 10 ; // line 1
a = ++a ; // line 2
a = a++ ; // line 3

System.out.println(a); // line 4
}
}

Output ::: ---> 11
But, why I am getting 11...its right but see below

Sir, Please observed the following variations also:::

Sir, if I am replace //line 3 with this following Expressions so it shows Unexpected Output Sir..

1) a = a++ + a++ ; replace Line 3 with This Expression
Output is :::--> 23 // But, why I am getting 23... instead of

2) a = a++ + a++ + a++ ; replace Line 3 with This Expression
Output is :::--> 36 // I think it is true but, , see below Expression

3) a = a++ + a++ + a++ + a++ ; replace Line 3 with This Expression
Output is :::--> 50 // But, why I am getting 50...instead of 48

4) a = a++ + a++ + a++ + a++ + a++; replace Line 3 with This Expression
Output is :::--> 65 // But, why I am getting 65... instead of 60


Sir, Please Please Please clear my doubts as early as am very tensed about it ....

akashjadhav
Автор

Sorry to say sir but the wordings are too small..
Cant see at all!!!
But explanation is good

anshikamishra
Автор

This is obviously bad code. If you have to ask your interviewees this question, then maybe you should rewrite your code.

IndellableHatesHandles