gaurav nayyar

Greenhorn
+ Follow
since Jul 13, 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 gaurav nayyar

The following lines of code
byte b = 0;
b += 1;

1.results in b having the value 1.
2.causes a compiler error.
3.will require a cast (byte) before 1.

answer is 1
but how is it different from
b= b+1
it generates a compiler error while above code doesnt why?
17 years ago
Hi Manfred ,
thanks for the explanation
Gaurav
17 years ago

what is demon thread ??
how it is used ??
can anybody help me ??
is this in scjp2 course??
17 years ago
class Servlets {
Servlets(String s) {
System.out.println(s);
}
void writeLn(String s) {
System.out.println(s);
}
}
class Form {
static Servlets s1 = new Servlets("J as in Jam");
Form() {
s2.writeLn("V as in Victor");
}
void writeLn(String s) {
System.out.println(s);
}
static Servlets s2 = new Servlets("A as in Apple");
}
class JSP {
Servlets s3 = new Servlets("S as in Sam");
static Servlets s4 = new Servlets("A as in Apple");
JSP() {
s4.writeLn("P as in Pollard");
}
void writeLn(String s) {
System.out.println(s);
}
static Servlets s5 = new Servlets("J as in John");
}
public class Q52 {
public static void main(String[] args) {
System.out.println("Trimming J from JSP in main()...");
new JSP();
f.writeLn("A Simple Example of static Initialization !");
j.writeLn("A Simple Example of Instance Initialization !");
}
static Form f = new Form();
static JSP j = new JSP();
}
What is the Output?
1.Prints
Trimming J from JSP in main()�
S as in Sam
P as in Pollard
A Simple Example of static Initialization !
A Simple Example of Instance Initialization !
J as in Jam
A as in Apple
V as in Victor
A as in Apple
J as in John
S as in Sam
P as in Pollard
2.Prints
J as in Jam
A as in Apple
V as in Victor
A as in Apple
J as in John
S as in Sam
P as in Pollard
Trimming J from JSP in main()�
S as in Sam
P as in Pollard
A Simple Example of static Initialization !
A Simple Example of Instance Initialization !

3.Prints
Trimming J from JSP in main()�
S as in Sam
A as in Apple
J as in John
P as in Pollard
A Simple Example of static Initialization !
A Simple Example of Instance Initialization !
J as in Jam
A as in Apple
V as in Victor
S as in Sam
A as in Apple
J as in John
P as in Pollard
4.Prints
J as in Jam
A as in Apple
V as in Victor
A as in Apple
J as in John
S as in Sam
P as in Pollard
Trimming J from JSP in main()�
A as in Apple
J as in John
S as in Sam
P as in Pollard
A Simple Example of static Initialization !
A Simple Example of Instance Initialization !
the answer is 2 but i cant get it
17 years ago
class InheritanceTest extends Process {
int x=18;
public static void main(String [] args) {
Process p = new InheritanceTest();
System.out.println(p.InheritanceTest('R'));
System.out.println(p.x);
}
InheritanceTest() {
System.out.println(true ^ true);
}
InheritanceTest(char c) {
System.out.println(c);
}
char InheritanceTest(char c) {
c='V';
return (char)c;
}
}
class Process {
int x=9;
Process() {
System.out.println("Starting Process...");
}
char InheritanceTest(int i) {
i='S';
return (char)i;
}
}
What is the Output?
1.Prints Starting Process �, false, �S� and 18
2.Prints false, �V� and 9
3.Prints true, �V� and 9
4.Prints Starting Process � , true, �V� and 9
5.Prints Starting Process �, false, �V� and 9
6.Prints Starting Process �, false, �V� and 18
7.Prints Starting Process �, false, �S� and 9
8.Prints Starting Process �, true, �R�, and 18
9.Prints Starting Process �, true, �V� and 18

the answer is 7
but how is it??
17 years ago
thanks to all of u now its clear
17 years ago
thanks to all of u now its clear
17 years ago
class Process {
byte b=127;
Process() {
this.methodA();
}
void methodA() {
System.out.println("Value of b is = " + b );
}
public static void main(String [] args) {
Processor p = new Processor();
}
}
class Processor extends Process {
byte b=126;
Processor() {
System.out.println("Value of b = " + b);
}
void methodA() {
System.out.println("Value of b = " + this.b);
}
}
What is the Output?
1.Prints Value of b = 0 and Value of b is = 126.
2.Compile-time error occurs.
3.Prints Value of b = 126 and Value of b = 126.
4.Prints Value of b = 127 and Value of b = 126.
the correct answer is :1
here i can't get how zero is printed ?
can anybody help me?
17 years ago
What will happen if you try to compile and run this code.
class Rectangle{
public int area(int length , int width) {
return length * width;
}
}
class Square extends Rectangle{
public int area(long length , long width) {
return (int) Math.pow(length ,2);
}
}
class Test{
public static void main(String args[]) {
Square r = new Square();
System.out.println(r.area(5 , 4));
}
}
1. Will not compile.
2. Will compile and run printing out 20
3. Runtime error
4. Will compile and run printing out 25
the right answer is :1 how??? i can't get it
17 years ago