Problem in calling method with object in another class

Hi All,

Please tell me the solution, I have problem in calling a method I am posting the code also

First Program:-

import java.io.*;

public class One

{

public One()

{

System.out.println("One:Object created");

}

public void display()

{

System.out.println("One:executing the display method");

}

static

{

System.out.println("One:executing the static block");

}

}

Second Program:-

import java.io.*;

public class Two

{

public Two()

{

System.out.println("Two:Object created");

}

public static void main(String arg[])throws Exception

{

System.out.println("Two:executing the main method");

System.out.println("Two:loading the class and creating the object::One");

Object o=Class.forName("One").newInstance();

System.out.println(o);

o.display();//displaying error here in compile time.

}

static

{

System.out.println("Two:executing the static block");

}

}

waiting for your answer,

thanks in advance,bye.

[1160 byte] By [siri2005a] at [2007-11-26 14:54:03]
# 1

> Hi All,

> Please tell me the solution, I have problem in

> calling a method I am posting the code also

>

> First Program:-

>

> import java.io.*;

> public class One

> {

> public One()

>

>System.out.println("One:Object created");

>

> public void display()

> {

> System.out.println("One:executing the display

> method");

>

> static

> {

> System.out.println("One:executing the static

> block");

>

> }

>

> Second Program:-

>

> import java.io.*;

> public class Two

> {

>public Two()

>

>System.out.println("Two:Object created");

> public static void main(String arg[])throws

> Exception

>

> System.out.println("Two:executing the main

> method");

> System.out.println("Two:loading the class and

> creating the object::One");

> Object o=Class.forName("One").newInstance();

> System.out.println(o);

> o.display();//displaying error here in compile

> time.

>

> static

> {

> System.out.println("Two:executing the static

> block");

>

> }

> waiting for your answer,

> hanks in advance,bye.

the line

o.display()

could be written as

((One)o).display();

PMJaina at 2007-7-8 8:42:27 > top of Java-index,Java Essentials,Java Programming...