jing zhao

Greenhorn
+ Follow
since Feb 21, 2001
Merit badge: grant badges
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 jing zhao

Thank you. Thank you!!!
I don't understand the "/*"?
public class Test5 {
public static void main (String args [])
{ /* This is the start of a comment
if (true) {
System.out.println("Done the test");
Test5 = new test5();
}
/* This is another comment */
System.out.println ("The end");
}
}
Ha Ha. I really understand it this time.
Thanks Cindy.

Originally posted by Cindy Glass:
When you created sun1 you made an explicit call to a particular constructor of the super class, so that was used. When you created sun and sun2 you did not call any of the constructors of the superclass, so the no-argument constructor was called for you. Some constructor of every superclass MUST be called before the constructor of the sub-class. Both line 1 and line 6 are caused by that.


How did line6 "Star" printed out? I understand output1--5 and7.
D.
1.Star
2.Star Wars1
3.Mercury is a Star.
4.Venus and Saturn are also Stars.
5.Star Wars2
6.Star
7.Earth
public class Star {
Star() {
System.out.println("Star");
}
Star(String s1) {
super();
System.out.println(s1 + " is a Star");
}
Star(String s2, String s3) {
this("Mercury");
System.out.println( s2 + " and " + s3 + " are also Stars");
}
public static void main(String [] args) {
Sun sun = new Sun();
Sun sun1 = new Sun("Venus");
Sun sun2 = new Sun("Mars", "Earth");
}
}
class Sun extends Star {
public Sun() {
System.out.println("Star Wars1");
}
public Sun(String v1) {
super(v1, "Saturn");
System.out.println("Star Wars2");
}
public Sun(String v2, String v3) {
if ( v2.substring(0, v2.length()).length() > v3.length())
System.out.println("Mission to Mars");
else
System.out.println("Earth");
}
}
Hi,
True.(Non-static inner class cannot have static members.)
But non-static inner class can have final static members is also true.
Try the program.
class ToplevelClass{
private static String msg="nonStatic inner class";
public NonStaticInnerClass makeInstance(){
return new NonStaticInnerClass();
}
class NonStaticInnerClass{
//final static var in the nonStatic InnerClass
private final static int staticVar=2;
private String string;
public NonStaticInnerClass(){string=msg;}
public void printMsg(){System.out.println(string);}
}
}
public class Client{
public static void main(String args[]){
ToplevelClass topRef=new ToplevelClass();
ToplevelClass.NonStaticInnerClass innerRef1=topRef.makeInstance();
innerRef1.printMsg();
}
}
I run the program, the 2 is right. In the add() method, it chooses to ignore the second paramter, that confused me.
Thanks all your help.

Originally posted by Manfred Leonhardt:
Hi Jing,
It chooses to ignore the second parameter in the add() method
The 'trick' here is that the Container class provides the add methods that are used by the AWT containers. It is up to each layout if it accepts and uses all the given parameters. In the case you have given, the GridLayout doesn't accept any constraints therefore it chooses to ignore the second parameter in the add() method. It is used to confuse you!
By default a GridLayout creates a single row with many columns. Therefore your result will be 2.
Regards,
Manfred.


Call 1-800-422-8020.
Hi Siva,
Thaks.
Yes,They are valid. But Why?
Is int x = 10 + +11; equal to int x=10+(+11);
int x = (char)(int)(10); equal to int x=(char)((int)10);

Originally posted by Sivalingam Sivasuthan:
Hi jing zhao,
Both (c and d)are Valid Statements, I compiled and got 21 and 10 respectively
Siva.
[


Why c and d are False?
c. int x = 10 + +11; is a invalid statment.
d. int x = (char)(int)(10); will give compiler error
The answer is 2.
What's the "North" and "South" use??
add(new Button("Three"), "North");
add(new Button("Four"), "South");
Thanks.
Q#7 What best describes the appearance of an application with the following code?
import java.awt.*;
public class FlowAp extends Frame{
public static void main(String argv[]){
FlowAp fa=new FlowAp();
fa.setSize(400,300);
fa.setVisible(true);
}
FlowAp(){
setLayout(new GridLayout());
add(new Panel());
add(new Button("One"));
add(new Button("Two"));
add(new Button("Three"), "North");
add(new Button("Four"), "South");
}
}
1) A Frame with buttons marked One to Four placed on a Panel
2) A panel and buttons marked One to four running from the left to right
3) A Frame with one large button marked Four in the Centre
4) An Error at run time indicating you have not set a LayoutManager properly
5) An Error at compile time indicating add is called with invalid parameters.