• 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

doubts from allover..... help me out

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
D1]
class ch_zero{
public static void main(String args[]){
if(0.0 >- 0.0){System.out.println("0.0 is greater");}
else
if(-0.0>0.0){System.out.println("-0.0 is greater");} //FIRST CHECK FOR 0.0
else
System.out.println("0.0 and -0.0 are equal");
System.out.println(0.0 ==-0.0);//SECOND CHECK FOR 0.0

if(0 >- 0){System.out.println("0 is greater");}
else
if(-0 >0){ System.out.println("-0is greater");} //FIRST CHECK FOR 0
else
System.out.println("-0 and 0 are equal");
System.out.println(0 ==-0);//SECOND CHECK FOR 0

System.out.println(Math.min(0.0,-0.0));
System.out.println(Math.max(0.0,-0.0));

System.out.println(Math.min(0,-0));
System.out.println(Math.max(0,-0));
}
}
in the above code both the cheks for 0.0 prove that 0.0 equals -0.0
then why does min() and max() methods give diff answers.
D2]
Assume that th is an instance holding a thread object. th.start() causes the thread to start running and eventually complete its execution. The object reference by th is not accessable any more and is garbage collected when the garbage collecter runs.

True
False
ans = false why?
D3]
The following code builds a GUI with a single button.
1. import java.awt.*;
2.
3. public class Q6 extends Frame {
4. setSize(500,500);
5. setLayout(new FlowLayout( ) );
6.
7.
8. Button b = new Button("Where am I ?");
9. Panel p1 = new Panel( );
10. p1.setLayout(new FlowLayout(FlowLayout.LEFT ));
11. Panel p2 = new Panel( );
12. p2.setLayout(new BorderLayout( ));
13. panel p3 = new Panel( );
14. p3.setLayout(new GridLayout( 3, 2 ) );
15.
16. p1.add(b);
17. p2.add(p1, BorderLayout.NORTH);
18. p3.add(p2);
19. add(p3);
20 }
21.
22. public static void main(String args[ ]) {
23. Q6 that = new Q6( );
24. that.setVisible(true);
25. }
26. }
i can't figure out the ans .can somebody help?
D4]
class ch_inner1{
ch_inner1(){
new inner().meth1(); // line 2
}
public static void main(String args[]){
//new ch_inner1().new inner().meth1(); // -----line 1
new ch_inner1();
}
class inner{
void meth1(){
System.out.println("inner");
}
}
}

in the ex D4]
if at line1 i try to instantiate inner class as follows and call the method meth1
new inner().meth1();
i get compile time error saying instane of outer class req.
from which i conclude that inner class can not be craeted without the instance of it's outer class.
but then again if i call method meth1() as in line two without instaniating outer class this time from the constructor of outer class i do not get any errors.
what's happening here.
pleas clarify my doubt.
 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
You are a glutten for questions.
1. Look at API documentation of Math.min and Math.max that take float parameters. The API is great for question answering...
2. Once a thread is completed (ie, dead) it can not be started anymore. But, the class that contains the run method is still valid! I can start another thread with the class again!
3. What's the question here? It looks like you are making a statement ...
4. What's happening is that in the constructor the compiler is supplying the outer class instance using 'this':
this.new inner().meth1();
But inside main you have no 'this' handle so the compiler is telling you to create your own if you want one.
Regards,
Manfred.
 
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes, in main method u don't have a this reference therefor u have to explicitly provide the this reference.Here in your question u have created an instance of the inner class from the context of outer class, remember whenever u create an instance in the outer context the innerclass class constructor and nonstaic method's alway's has outer class reference, u don't have to do anything that reference is implicitly available to all the nonstaic member's of nonstatic innerclass.
 
When you have exhausted all possibilities, remember this: you haven't - Edison. Tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic