Vinoth Kumar S.

Greenhorn
+ Follow
since Apr 04, 2006
Merit badge: grant badges
For More
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 Vinoth Kumar S.

Hi Jothi Shankar,

There are two cases,

Case 1: When you Override a method in child class...
import java.io.*;

class Parent{

public void m1() throws IOException {}

}

class Child extends Parent{
public void m1() {} // You no need to handle any exception (or) not suppose to declare any exception wider than IOException
}

------------------------------------------------------------------------
Case 2: When you Overload a method in child class...
import java.io.*;

class Parent{

public void m1() throws IOException {}

}

class Child extends Parent{
public void m1(int i) {} // You can leave it blank (or) You can declare any exception wider than IOException
}


Hope this will be useful for you...
Hi Ranchers,

I am using JDK 1.5. I have compiled this code. I am getting the output as 5. Give the reason how the main()[static method] able to access the instance variable.



public class StaticTest{
int value=5;
public static void main(String args[]){
System.out.println(new StaticTest().value);
}
}
Hi Shankar,

Comment out the printStaticValue() method and try to compile
Hi just comment our the printStaticValue() method and try to compile now
Jothi Shankar Kumar pls try this code. and give your valuable comments. This works for me.
Consider the following code,

public class StaticTest{

int value=5;
static int staticValue=5;


public void printValue(){
System.out.println(value); // Prints 5
System.out.println(staticValue); // Prints 5
}

public static void printStaticValue(){
System.out.println(staticValue); // Prints 5
System.out.println(value); // Error: Non-Static value cannot be referenced from a static context 5
}

public static void main(String[] args){
System.out.println(value); // Prints 5}
}
}

In the above code both printStaticValue() and main() static methods.
Why the main() method prints 5
Congratulations
17 years ago