Results 1 to 2 of 2
Thread: Doubt in Package-Object creation
- 06-02-2010, 05:55 AM #1
Member
- Join Date
- Jun 2010
- Posts
- 1
- Rep Power
- 0
Doubt in Package-Object creation
Hi.. This is my first file: Protection.java
This is my Second File:SecondPackage.java under the same package p1Java Code:package p1; public class Protection { int n =1; private int n_pri=2; protected int n_pro=3; public int n_pub=4; public Protection(){ System.out.println("Base Constructor:"); System.out.println("n: "+n); System.out.println("n_pri: "+n_pri); System.out.println("n_pro: "+n_pro); System.out.println("n_pub: "+n_pub); } }
and here is the Test File:Java Code:package p1; class SamePackage { Protection p1= new Protection(); System.out.println("Same Package Constructor"); System.out.println("n: "+p1.n); //System.out.println("n_pri: "+p1.n_pri); System.out.println("n_pro: "+p1.n_pro); System.out.println("n_pub: "+p1.n_pub); }
My doubt is why System.out.println Statements are shown as error here?. I know if i put the System.out.println statements inside SamePackage constructor it wont show any error... but I want to know why --Java Code:package p1; public class Demo { public static void main(String args[]){ Protection Ob1= new Protection(); Derived Ob2= new Derived(); SamePackage Ob3= new SamePackage(); } }
cant be put without a constructor in class SamePackage?Java Code:System.out.println("Same Package Constructor"); System.out.println("n: "+p1.n); //System.out.println("n_pri: "+p1.n_pri); System.out.println("n_pro: "+p1.n_pro); System.out.println("n_pub: "+p1.n_pub);
- 06-02-2010, 06:39 AM #2
Cross posted and already answered, not that a cross poster would bother to inform this forum of that.
New To Java - Doubt in Package-Object creation
db
Similar Threads
-
String Object Creation
By indranil in forum New To JavaReplies: 1Last Post: 04-13-2010, 11:30 AM -
Accessing non-static fields from another class, before object creation
By mlad in forum New To JavaReplies: 3Last Post: 03-24-2010, 12:24 AM -
object creation
By enygma in forum Java AppletsReplies: 0Last Post: 01-05-2010, 10:01 AM -
Object creation and construstion
By abimaran in forum New To JavaReplies: 8Last Post: 12-15-2009, 09:58 AM -
Object creation and memory issues
By bugger in forum New To JavaReplies: 11Last Post: 11-29-2007, 12:56 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks