Morgan Subram

Greenhorn
+ Follow
since Jan 03, 2001
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Morgan Subram

public class test1 implements Runnable
{
public static int j = 0;
public void run()
{
try {
Thread.sleep(5000);
j = 10;
} catch (InterruptedException e)
{
j = 8;
}
}
public static void main(String arg[])
{
test1 test=new test1();
Thread t = new Thread(test);
t.start();
try{t.join();}catch(InterruptedException e ){}
System.out.println(""+j);
}
}
String s1,s2,s3,s4;
s1 = "Hello"; //Object Created
s2 = s1;
s3 = s2 + "Pal"; //Two Objects Created --StringBuffer and append
s4 = s3;
So the answer is three

public class ConsTest{
public ConsTest(){
int i=0;
int j=3;
return;
}
public static void main(String args[]){ConsTest t=new ConsTest();}
}
This compiles and runs perfectly
Java specifications says that a constructor body can have
a return statement but the return statement should not
have a expression
Can anybody explain then what is the purpose of
a return statement at all in a constructor body
public class TestThis{
public static void main(String args[]){
System.out.println(1 + 2 + "Strange");
System.out.println("Strange" + 1 + 2);
}
}
After compiling this
when you run this
The first output is 3Strange
why is the second output Strange12 rather than Strange3 ?
Try this
public class inter1{
public static void main(String argv[]){
inter1 mi = new inter1();
}
inter1(){
boolean b=true;
if(b!=false){ // Changed Here
System.out.println("The value of b is"+b);
}
}
}

This will work and this further clarifies things
public class ClassTest{

public static class Inner{
public void good() {
int i=0;
}
private static class InnerInner{
private static class InnerInnerInner {
private static void k() {
System.out.println("In InnerInnerInner static method");
}

}

}
}


public static void main(String [ ] argc){
ClassTest.Inner.InnerInner.InnerInnerInner c= new ClassTest.Inner.InnerInner.InnerInnerInner();
c.k();
}
}
Consider this piece of code and you will agree
public class ClassTest{

public static class Inner{
public void good() {
int i=0;
}
private static class InnerInner{
private static class InnerInnerInner {
private static void k() {
System.out.println("In InnerInnerInner static method");
}

}

}
}


public static void main(String [ ] argc){
ClassTest.Inner.InnerInner.InnerInnerInner c= new ClassTest.Inner.InnerInner.InnerInnerInner();
c.k();
}
}
This works
Hi,
public class ClassTest{

public static class Inner{
public void good() {
int i=0;
}
private static class InnerInner{
private static class InnerInnerInner {
private static void k() {
System.out.println("In InnerInnerInner static method");
}

}

}
}


public static void main(String [ ] argc){
ClassTest.Inner.InnerInner.InnerInnerInner c= new ClassTest.Inner.InnerInner.InnerInnerInner();
c.k();
}
}
This piece of code works..

Some of the familiar Unchecked Exceptions are
NullPointerException
ArithmeticException
ArrayIndexOutOfBoundsException
ClassCastException
But Strangely NumberFormatException is a UncheckedException
Hi Peter,
I wish to correct method setName should have void as return type
class Person {
private String Name;
public void setName(String Name)
{
this.Name = Name;
}
}
Thanks..
24 years ago
Let us consider two cases here
Case 1:

Case 2 :

In Case 1 there is no concurrency
While in Case 2 Concurrency exists
Hope this makes it clear
[
Hi,
I have added the [ code] [ /code] UBB tags to your code. I hope you don't mind. It is recommended you use these tags when writing code. ]
[This message has been edited by Rahul Mahindrakar (edited January 15, 2001).]