Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!

james gong

Ranch Hand
+ Follow
since May 29, 2001
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 james gong

the output seems doesnt print out according the order you give.
in my opinion the output should be ;
456
123
AAA
CCC
BBB

pls read the following code:
class A
{
public A()
{
System.out.println("AAA");
}

System.out.println("456");

}
public class B extends A
{
B()
{
this(12);
System.out.println("BBB");
}
B(int x)
{
System.out.println("CCC");
}

System.out.println("123");

public static void main(String[] args)
{
new B();
}
}
the out is:
456
AAA
123
CCC
BBB

But I think the when the just the time the class is loaded the static method should be execute [the system.out.print() is static method ],as a result, the 123 should be change to after the AAA,I think the out should be :
456
123
AAA
CCC
BBB

I am wrong ,I am sure .but I am confused .I cant find myself on the issue.I will be very glad if somebody clear me .
Hi swati bannore
Thank you very much ,you are greate!
I know the difference about int[] a,b,c and int a[] ,b ,c;
7 Which of the given choices are true?Select any two.
1 class Q3
2 {
3 public static void main(String arg[])
4 {
5 int[] a,c,d[];
6 int b[]=new int[0];
7 }
8 }
options :
1) All the variables a,b,c,d are arrays.
2) Only a,d,b are arrays.
3) We can declare an array with zero element.
4) We cannot declare an array with zero element.
i thought the answers were 2& 3 but when i checked it was as 1 & 3. please let me know whether i am correct or not and why in case i am wrong .
import java.io.*;
public class OutOut
{
public static void main(String args[]) throws IOException
{
PrintStream pr = new PrintStream(new FileOutputStream("outfile"));
System.out = pr;
System.out.println("Lets see what I see now??");
}
}
1. The code causes a compiler error. out is a declared final in
System and cannot be assigned to pr.
2. The code causes a runtime Exception due the assignment to a
final variable.
3. The code compiles and runs success fully. A file
called "outfile" is created and "Lets see what I see now??"
is printed in the same.
the Given ans:1
in my option :2
I can distinct the diference from ans1 and ans2.Somebody kind enough to clearfy me?
Would somebody kind enough to give me a completely list about my question?
you may reference the question--what happen if all the constructor of a class be declared as private?
read the code first,why the sb1.equals(sb2) return a false valeu?
/*******************************************************//
public class TestClass
{
public static void main(String Args[])
{
StringBuffer sb1 = new StringBuffer("String");
StringBuffer sb2 = new StringBuffer("String");
String sb3 = new String("String");
String sb4 = new String("String");

if(sb1.equals(sb2))
{
System.out.println(" StringBuffer:I am reache here!");
}
else
System.out.println("StringBuffer:sorry!");
if(sb3.equals(sb4))
{
System.out.println(" String:I am reache here!");
}
else
System.out.println("String:sorry!");
}
}
//*******************************************************//
I think the ans1 that "Cannot be instantiated by any other class" are right ,but I am not so claerly about it ,somebody can clearfy my confusition about the concept.
I think ans1 is right.but i have no clearly evidence.somebody can clear my mind.
A class which has all its constructors declared as private
1.Cannot be instantiated by any other class.
2.Cannot be extended.
3.Both i and ii.
4.has to be declared final.
key is ;2
but i cant pull out myself from ans1 and ans2,and I also cant make me clearly among the two ans.concern the case please say something .
interface One
{
public void someMethod();
}
public class One_impl implements One
{
public native void someMethod();
}

Assuming that the native method is not provided in any local library, an attempt to compile and run the above lines of code will cause

1. Compilation error - implimentations can never be native.
2. Compilation error - method not found in local libraries.
3. Runtime Exception - method not found in local libraries.
4. Compilation successfull but runtime error is thrown if and only if the method someMethod of class One_impl is called.
given ans:4
I dont know clearly about the given ans 4 enve I got the ans.
why a runtime error is thrown if and only if the method someMethod of class One_impl is called.

public class ADirtyOne
{
private final int i =10;
private byte k = i;

}

I had thought the code wouldn't compile(it need a explicit cast),but when I compile ,it compile clearly without any warning.
I thought the int is wide than byte ,so when convert a int to a byte ,need a explicit cast( private byte k=(byte)i
Am I right?
read following code,why the code1 compile while the code2 not.Give me something about the item.
code1:
public class AQuestion
{
public static void main(String args[])
{
System.out.println("Before Try");
try
{
}
catch(Throwable t)
{
System.out.println("Inside Catch");
}
System.out.println("At the End");
}
}
code2:
public class AQuestion
{
public static void main(String args[])
{
System.out.println("Before Try");
try
{
}
catch(java.io.IOException t)
{
System.out.println("Inside Catch");
}
System.out.println("At the End");
}
}
the code1 ans :3(No compiler error. The lines "Before Try" and "At the end" are printed on the screen. )
the code2 ans :1(Compiler error complaining about the catch block where no IOException object can ever be thrown. )