By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,106 Members | 2,335 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,106 IT Pros & Developers. It's quick & easy.

calling a class from another package

P: 1
calling a class from another package
Sep 14 '18 #1
Share this Question
Share on Google+
1 Reply


P: 18
try this code for call a class from another package
new package
Expand|Select|Wrap|Line Numbers
  1. package people;
  2.  
  3. class Children{
  4.     private String name;
  5.  
  6.     public Children( ) {
  7.         name = "Unknown";
  8.     }
  9.  
  10.     public String getName() {
  11.         return name;
  12.     }
  13.  
  14.     public void setName(String name) {
  15.         this.name = name;
  16.     }
  17. }
  18.  
calling a class in another package
Expand|Select|Wrap|Line Numbers
  1. package test;
  2. import people.Children;
  3.  
  4. public class Test {
  5.  
  6.     public static void main(String[] args) {
  7.  
  8.         Children children= new Children(); //declare and initialize
  9.     }
  10. }
Apr 15 '19 #2

Post your reply

Sign in to post your reply or Sign up for a free account.