calling a class from another package

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • monah1957
    New Member
    • Sep 2018
    • 1

    calling a class from another package

    calling a class from another package
  • AjayGohil
    New Member
    • Apr 2019
    • 83

    #2
    try this code for call a class from another package
    new package
    Code:
    package people;
     
    class Children{
        private String name;
     
        public Children( ) {
            name = "Unknown";
        }
     
        public String getName() {
            return name;
        }
     
        public void setName(String name) {
            this.name = name;
        }
    }
    calling a class in another package
    Code:
    package test;
    import people.Children;
     
    public class Test {
     
        public static void main(String[] args) {
           
            Children children= new Children(); //declare and initialize
        }
    }

    Comment

    Working...