Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting output of other class.

 
rohit shekhar
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was trying this...
In a common package (in eclipse) i placed two files as follows:-

1) p1.java

public class p1 {
public static void main(String[] args)
{
System.out.println("Hello!");
p2 p = new p2();
p.disp();
}
}
class p2
{
void disp()
{
System.out.println("From class p2");
}
}

2) p2.java

class p3
{
// strange!! execute this file we will get output of p1.java
}
class p4
{

}



if we will execute p2.java it shows output of p1.java
please explain.
 
Astha Sharma
Ranch Hand
Posts: 250
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you might be using this command for execution-
java p2
 
naveen yadav
Ranch Hand
Posts: 384
Java MyEclipse IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

if you can please provide complete code with command line options
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic