Win a copy of React Cookbook: Recipes for Mastering the React Framework this week in the HTML Pages with CSS and JavaScript forum!


+ Follow
since Feb 08, 2000
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by RajeshParab

public class Test{
public static void main(String argv[]) {

Long a = new Long(7);
Integer b = new Integer(7);
if (a.equals(b)) System.out.println("Equal");
else System.out.println("Not Equal");
Test m = new Test();
Output is "Not Equal".
I thought answer is "Equal". ??? Where i am wrong???
public class Test {
public static void main(String args[]) {
StringBuffer a = new StringBuffer("One");
StringBuffer b = new StringBuffer("Two");
System.out.println("a is "+ a +"\nb is " + b);
static void swap (StringBuffer a, StringBuffer b) {
a.append(" more");
What will be the output?
a. a is One
b is Two
b. a is One
b is One
c. a is One more
b is One more
d. a is One more
b is Two
e. a is One more
b is Two more
asnwer is d
i thougth answer is c
a.append(" more"); // now a is "One more"
b=a; // now b = a means b is also "One more"
Correct me where i am wrong ???
Which of the following statements about garbage collection are true?
Select all valid answers

a) Only objects with no references will be garbage collected
b) Unused objects can be immediately garbage collected by setting them to null
c) Unused objects can be immediately garbage collected by executing 'System.gc()'
d) Setting an object to null will make it availabe for garbage collection
e) Garbage collection cannot be forced
answer is d & e
i thought a, d & e. why not a???
What are the proper ways to initialize the static variables SIZE and MIN_VALUE ?
01: class Base
02: {
03: static final int SIZE;
04: static float MIN_VALUE;
06: Base() { }
07: void test() {
08: System.out.println("Base.test()");
09: }

Select all valid answers.

a) Add the following lines to Base Class
static {
SIZE = 10;
MIN_VALUE = 10.3f;
b) Add the following lines to Base Class
SIZE = 10;
MIN_VALUE = 10.3f;
c) Add the following lines to Base Class constructor
SIZE = 10;
MIN_VALUE = 10.3f;
d) Modify lines 03 and 04 as
static final int SIZE = 10;
static float MIN_VALUE = 10.3f;
Answer is A & D
but i don't agree with A. What will happen to final modifier of variable SIZE. and is it possible to change final modifier in static varible???
What will be the output when you compile and execute the following program.


class Base
void test() {

public class Child extends Base {

Child(int i) { test (); }

Child(float f) { this ((int)f); }

void test() {

static public void main(String[] a) {
new Child(10.8f).test();
Select most appropriate answer.

a) Child.test() //true
b) Compilation Error: No default constructor ( constructor matching Base())
found in class Base.
c) Runtime Error: No default constructor ( constructor matching Base())
found in class Base.
d) Compilation Error: Cannot call this() from a constructor.
I don't know how we get this output. help me here???
A sleeping Thread can be interrupted by interrupt method of the particular Thread instance, which generates an Interrupted Exception
class Outer { // outer class
void test() {
final int outer_x = 100;
public class Inner { // Inner class
void display() {
System.out.println("display: outer_x =" + outer_x);
Inner inner = new Inner();
class Parent {
public static void main(String args[]) {
Outer outer = new Outer();
I am getting compilation error for above code. but if i remove public modifier from inner class. It is working fine. and i am getting proper result. Can any body help me here???
?? Can i use any other modifier for inner class for ex. in above ex. its working fine for default modifier but not for other modifiers.
?? Is there any way to instantiate inner class out of Outer class. For ex. In above ex. can i use Inner class reference in Parent class. (other that static)
[This message has been edited by Tony Alicea (edited February 20, 2000).]
1 public class StrBufTest {
2 public void method1(StringBuffer s1, StringBuffer s2){
3 s1.append("There");
4 s2 = s1;
5 }
public static void main(String[] args){
StringBuffer sb1 = new StringBuffer("Hello");
StringBuffer sb2 = new StringBuffer("Hello");
StrBufTest sbt = new StrBufTest();
sbt.method1(sb1, sb2);
System.out.println("sb1 is " + sb1 + "\nsb2 is " + sb2);
Answer is: sb1 is "HelloThere"; sb2 is "Hello".
When we say s2 = s1. It creates copy of reference. both should have save content. How come sb1 and sb2 is different???
Is there any difference between "==" operator and equals() or both can be use for same thing.
class Test1 {
public static void main(String args[]) {
String strOb1 = "First String";
String strOb2 = "Second String";
String strOb3 = "First String";
String strOb4 = strOb1;
System.out.println("strOb1 == strOb2");
System.out.println("strOb1 != strOb2");
System.out.println("strOb1 == strOb3");
System.out.println("strOb1 != strOb3");
System.out.println("strOb1 == strOb4");
System.out.println("strOb1 != strOb4");
if(strOb1 == strOb2)
System.out.println("not equal");
if(strOb1 == strOb3)
System.out.println("not equal");
if(strOb1 == strOb4)
System.out.println("not equal");
output is
strOb1 != strOb2
strOb1 == strOb3
strOb1 == strOb4
not equal
I found a nice example why it is so.
class Switch {
public static void main(String args[]) {
for(int month=1;month<=12;month++) {
String season;
switch (month) {
case 12:
case 1:
case 2:
season = "Winter";
case 3:
case 4:
case 5:
season = "Spring";
case 6:
case 7:
case 8:
season = "Summer";
case 9:
case 10:
case 11:
season = "Autum";
season = "Bogus Month";
System.out.println("Month " +month+" is in the season + ".");

This make sense:
break statement can be effectively use in switch statment.
Any Class containes an abstract method must be declare abstract.
But why it is not vice versa???
For ex. If class declare as abstract and method is not abstract it works fine.
abstract class Test1 {
public static void main(String args[]) {
int i = 0;
Output : 0
class Test1 {
public static void main ( String args[])
int i = 012;
It prints 10 on standard output.
why not 12???
public class Calc {
public static void main (String args []) {
int total = 0;
for (int i = 0, j = 10; total > 30; ++i, --j) {
System.out.println(" i = " + i + " : j = " + j);
total += (i + j);
System.out.println("Total " + total);
A. Produce a runtime error
B. Produce a compile time error
C. Print out "Total 0"
D. Generate the following as output:
i = 0 : j = 10
i = 1 : j = 9
i = 2 : j = 8
Total 30
I am kind of wondering how come asnwer is C.
Can anybody help me here.

Applet is not included in Exam Objective.
So no question on Applet.