Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java structure example

   class Employee {
       private String name;
       private int code;

   // constructor
   public Employee(String name, int code) {
      this.name = name;
      this.code = code;
   }

       // getter
       public String getName() { return name; }
       public int getCode() { return code; }
       // setter

       public void setName(String name) { this.name = name; }
       public void setCode(int code) { this.code = code; }
    }
    
Employee[] arr = new Employee[100];  // new stands for create an array object
arr[0] = new Employee("Peter", 100); // new stands for create an employee object
arr[1] = new Employee("Mary", 90);
Comment

java structure example


   class Employee {
       private String name;
       private int code;

   // constructor
   public Employee(String name, int code) {
      this.name = name;
      this.code = code;
   }

       // getter
       public String getName() { return name; }
       public int getCode() { return code; }
       // setter

       public void setName(String name) { this.name = name; }
       public void setCode(int code) { this.code = code; }
    }

Comment

java structure

 class Employee {
       private String name;
       private int code;

   // constructor
   public Employee(String name, int code) {
      this.name = name;
      this.code = code;
   }

       // getter
       public String getName() { return name; }
       public int getCode() { return code; }
       // setter

       public void setName(String name) { this.name = name; }
       public void setCode(int code) { this.code = code; }
    }
And when you want to create multi employees, create array just like in C:

Employee[] arr = new Employee[100];  // new stands for create an array object
arr[0] = new Employee("Peter", 100); // new stands for create an employee object
arr[1] = new Employee("Mary", 90);
Comment

PREVIOUS NEXT
Code Example
Java :: For loop Java Example to Iterate an Array 
Java :: declare generic set java 
Java :: static class java 
Java :: initialize hashmap java 
Java :: jcolorchooser in java 
Java :: If you are using the git profile, you need to set a Git URI in your configuration. If you have set spring.cloud.config.server.bootstrap=true, you need to use a composite configuration. 
Java :: java set 
Java :: index of an array procesing 
Java :: anagram java 
Java :: main method in java 
Java :: priority queue java comparator 
Java :: this keyword java 
Java :: how to disable screenshot in react native 
Java :: regex s+ 
Java :: how to find armstrong numbers in java 
Java :: check if char is letter or digit 
Java :: align button to the left in JPanel 
Java :: How to summon an item in bukkit 
Java :: build libgdx jar 
Java :: sorting methods in java 
Java :: how to set path for java in windows 10 
Java :: object creation in java 
Java :: java foreach method 
Java :: make a textarea not editable javafx 
Java :: android java show hide keyboard in AndroidManifest 
Java :: cannot find symbol iterator in java 
Java :: java run class file 
Java :: Explain try & catch finally block in Java 
Java :: csv compare java 
Java :: Pattern Programs in Java. 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =