Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp

Priyanka Leo

Greenhorn
+ Follow
since Sep 14, 2020
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Priyanka Leo

no this was one of the question from the book by Mala Gupta. and the single = was mentioned in the question
thanks for the reply I am able to understand the logic now.
Guys is the below object creation possible even though the class Phone and Interface Roamable are not related.

Can someone please explain me this program logic.
According to me i belive the line 1(commented) will increment and print . but the actual scenario i get no output.
class Fish
{
static byte count;
}
class mainn
{
  public static void main(String[] args)
   {
     boolean hungry = false;
while(hungry = true)
{
          ++Fish.count;
}
System.out.println(Fish.count); // line 1
  }
}
thanks for the clarification guys!!
thank you guys now i understood the logic!!
Guys i am currently preparing for OCA 1Z0 -808 exam
i have a doubt in the below code . I assume that the output will be
1111
2222
(explaination:
int m = 1111;

   {
       m = m++; // the value is 1111}
and when it comes here
int methodOfY()
   {
       return m-- + --m;// the value will be 1112 + 1110
   })

But the output that i get is
1111
2220

Could someone please help me understand the logic behind this code

class X
{
   int m = 1111;

   {
       m = m++;

       System.out.println(m);
   }
}

class Y extends X
{
   {
       System.out.println(methodOfY());
   }

   int methodOfY()
   {
       return m-- + --m;
   }
}

public class MainClass
{
   public static void main(String[] args)
   {
       Y y = new Y();
   }
}
Guys i am currently preparing for OCA 1Z0 -808 exam and i came across the below code which Outputs
Output :
Base
Dervied
Dervied


But what i expected was
Base
Base
Dervied

Could someone explain the logic of this. Thanks in advance guys!!

class Base
{
public void Print()
{System.out.println("Base");
}
}
class Derived extends Base
{
public void Print()
{
System.out.println("Dervied");
}
}
class mainn
{
public static void DoPrint (Base o)
{
o.Print();
}
public static void main(String[] args)
{
Base x = new Base();
Base y = new Derived();
Derived z = new Derived();
DoPrint(x);
DoPrint(y);
DoPrint(z);
}
}