• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Questions from ablilash's mockexam

 
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Question 1.
public class AQuestion
{
private int i = giveMeJ();
private int j = 10;
private int giveMeJ()
{
return j;
}
public static void main(String args[])
{
System.out.println((new AQuestion()).i);
}
}
Answers

1) Compiler error complaining about access restriction of private variables of AQuestion.
2) Compiler error complaining about forward referencing.
3) No Compilation error - The output is 0;
4) No Compilation error - The output is 10;
Q.2 public class ADirtyOne
{
public static void main(String args[])
{
System.out.println(Math.abs(Integer.MIN_VALUE));
}
}
an attempt to compile and run the above class will
1. Cause a compiler error.
2. Cause no error and the value printed on the screen is less than zero.
3. Cause no error and the value printed on the screen is one more than Integer.MAX_VALUE
4. Will throw a runtime exception due to overflow - Integer.MAX_VALUE is less in magnitue than Integer.MIN_VALUE.
how to find out the absolute value.
Q.3
public class ADirtyOne
{
public static void main(String args[])
{
System.out.println(Math.min(0.0,-0.0));
}
}
An attempt to compile and run the above class will

1. Cause a compiler Error.
2. Cause no error and print the value 0.0 on the screen.
3. Cause no error and prints the value -0.0 on the screen.

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
i tryed out all the 3 codes
well,
1> it compiles fine & executes & prints the output 0.
2> it compiles & prints the vale less than 0 , i.e it prints a negative large value.
3> actually , internally if u compare 0.0 & -0.0 they r both equal, but in this case when u want to print the min of the two, the output printed is -0.0.
if u had wanted Math.max(0.0,-0.0), it prints 0.0 as the output.
all the above ans for the code u gave , i have answered only after actually executing the code on my system.
all the best
Dipali

Originally posted by shabbir zakir:
Question 1.
public class AQuestion
{
private int i = giveMeJ();
private int j = 10;
private int giveMeJ()
{
return j;
}
public static void main(String args[])
{
System.out.println((new AQuestion()).i);
}
}
Answers

1) Compiler error complaining about access restriction of private variables of AQuestion.
2) Compiler error complaining about forward referencing.
3) No Compilation error - The output is 0;
4) No Compilation error - The output is 10;
Q.2 public class ADirtyOne
{
public static void main(String args[])
{
System.out.println(Math.abs(Integer.MIN_VALUE));
}
}
an attempt to compile and run the above class will
1. Cause a compiler error.
2. Cause no error and the value printed on the screen is less than zero.
3. Cause no error and the value printed on the screen is one more than Integer.MAX_VALUE
4. Will throw a runtime exception due to overflow - Integer.MAX_VALUE is less in magnitue than Integer.MIN_VALUE.
how to find out the absolute value.
Q.3
public class ADirtyOne
{
public static void main(String args[])
{
System.out.println(Math.min(0.0,-0.0));
}
}
An attempt to compile and run the above class will

1. Cause a compiler Error.
2. Cause no error and print the value 0.0 on the screen.
3. Cause no error and prints the value -0.0 on the screen.


 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic