Win a copy of Spring Boot in Practice this week in the Spring forum!

rainbow

Ranch Hand
+ Follow
since Sep 10, 2000
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 rainbow

hi all:
I think the only correct answer is 2.just try below code to validate it.
import java.awt.*;
public class test extends Frame{
public static void main(String agrs[]){
test t = new test();
}
test(){
super("my frame");
setLayout(new GridLayout(2,2));
setSize(100,100);
add(new Button("botton1"));
add(new Button("botton1"));
add(new Button("botton1"));
add(new Button("botton1"));
add(new Button("botton1"));
setVisible(true);
}
}
you will find the Frame's size isn't increased to allow the buttons full showed.In the contrast,the Button will be truncated.
Geek,you are right.
the constructor of Math is private.So Math can't be instanced.
Thanks all.
hi:
The code shouldn't include "implements A",it's a mistake.Ignore this,the correct answer should be A.if remove ";",the result will be B.It is truth.If you don't beleive it,you can try to run it.
look at below question:
Examine the following code which includes an inner class:

public final class Test4 implements A {
class Inner {
void test() {
if (Test4.this.flag); {
sample();
}
}
}
private boolean flag = false;
public void sample() {
System.out.println("Sample");
}
public Test4() {
(new Inner()).test();
}
public static void main(String args []) {
new Test4();
}
}

What is the result:
A. Prints out "Sample"
B. Program produces no output but terminates correctly.
C. Program does not terminate.
D. The program will not compile
Select the most appropriate answer.
Please pay attention to the bold sentence,it runs strangely.

Greek:
Why do you think the Math class constructor is private.I can't find the constructor description in java 2 specification document.
Normally if there is no explicit constructor,the system will provide a default constructor for the class.And the default constructor's access modifier is same as the class.i.e. a public class will have a public default constructor.Math class is public.So I think its constructor is also public.
if my opinion is wrong.pls correct it.
Rainbow
Which of the following statements are true about the fragment below?
import java.lang.Math;
public class Test {
public static void main(String args[]) {
Math m = new Math();
System.out.println(m.abs(2.6);
}
}
A) Compiler fails at lin 1
B) Compiler fails at line 2
C) Compiler fails at the time of Math class instantiation
D) Compiler succeeds.
why can't Math class be instanced?
Math is public final class.It's no reasonable that Math class can't be instanced.
hi:
It's a new keywords in java 2.this is true.if you still doubt it,you can try to test it.
int strictfp=1; //will compile with error.
wish some help to you.
sorry,I mistaked the UBB code.let me try it again.
hi all:
Quote from JLS:
The keywords const and goto are reserved, even though they are not currently used. While true and false might appear to be keywords, they are technically Boolean literals .Similarly, while null might appear to be a keyword, it is technically the null literal .
I think Sun shouldn't test the difference between keywords and reserve words.
Rainbow
hi all:
Quote from JLS:
{b]The keywords const and goto are reserved, even though they are not currently used. While true and false might appear to be keywords, they are technically Boolean literals .Similarly, while null might appear to be a keyword, it is technically the null literal .[/b]
I think Sun shouldn't test the difference between keywords and reserve words.
Rainbow
Thank you ,Ajith Kallambella.
but if I use the search tool,what search word can I fill?I don't know how the serarch engine work.do you know about it?
rainbow
so goto,const is reserve words but not keywords.
am I right?
Which of the following statements are true?
A) An anonymous class cannot have any constructors
B) An anonymous class can only be created within the body of a method
C) An anonymous class can only access static fields of the enclosing class
D) An anonymous class instantiated and declared in the same palce.
who can tell me the correct answers and the reason?
I don't know if the difference between keyword and reserve word.
is goto a keyword or a reserve word?
who can help me?
class NormalClass{
static class NestedClass{
}
}
public class test{
public static void main(String agrs[]){
test t = new test();
t.out();
}
void out(){
NormalClass c = new NormalClass();
NormalClass.NestedClass n = c.new NestedClass();
}
}
above code will compile and run correctly.but if I change the code to below:
class NormalClass{
static class NestedClass{
}
}
public class test{
public static void main(String agrs[]){
test t = new test();
t.out();
}
void out(){
//NormalClass c = new NormalClass();
NormalClass.NestedClass n = new NormalClass().new NestedClass();
}
}

it will compile without error,but run incorrectly.
who can explain it to me?Thanks a lot.
below is a question from Marcus Green's site.
Given the following code what will be the output?
class ValHold{
public int i = 10;
}
public class ObParm{
public static void main(String argv[]){
ObParm o = new ObParm();
o.amethod();
}
public void amethod(){
int i = 99;
ValHold v = new ValHold();
v.i=30;
another(v,i);
System.out.println(v.i);
}//End of amethod
public void another(ValHold v, int i){
i=0;
v.i = 20;
ValHold vh = new ValHold();
v = vh;
System.out.println(v.i+ " "+i);
}//End of another
}
1) 10,0, 30
2) 20,0,30
3) 20,99,30
4) 10,0,20
who can tell me which answer is correct and why is it correct?
Thank a lot.