Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

setter getter array java

//Student class containing array of object 'leture'
public class Student {
    private Lecture[] lecture;
//lecture setter method
    public void setStudentLecture(Lecture[] lecture) {
        this.lecture = lecture;
    }
//lecture getter method
    public Lecture[] getStudentLecture() {
        return lecture;
    }


//main method for running code
    public static void main(String[] args) {
//Student object declaration
        Student student = new Student();
//lecture object declaration
        Lecture[] lectures = new Lecture[3];
//setting values for lecture names for each array element
        lectures[0] = new Lecture("Physics");
        lectures[1] = new Lecture("Mathematics");
        lectures[2] = new Lecture("Chemistry");
//Adding those elements to the array of lecture objects in Student Class
        student.setStudentLecture(lectures);
//displaying array of lecture objects
        Lecture[] lectures1 = student.getStudentLecture();
        for (int i = 0; i <lectures1.length; ++i) {
            System.out.println(lectures1[i].getName());
        }
    }
}


//Lecture class with name attribute
public class Lecture {
    private String name;
//setter for name value 
    public Lecture(String name) {
        this.name = name;
    }
//getter for name value
    public String getName(){
        return name;
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: vue composition watch 
Java :: java remove item from list 
Java :: new keyword in java 
Java :: write file java 
Java :: iterate over multi array java 
Java :: abstract method declaration 
Java :: spring @value default value 
Java :: Java How to use List? 
Java :: what is outer class in java 
Java :: StackAsMyArrayList 
Java :: java Convert a string IPv4 IP address to the equivalent long numeric value. 
Java :: Implementation of LinkedHashMap Class in Java map 
Java :: how to compute age from local date 
Java :: java add a list to a list 
Java :: minecraft detect specific item in chest with custom name 
Java :: java mostrar resultados ventana grafica 
Java :: exceptions in java 
Java :: interface java 
Java :: read many lines from stdn java 
Java :: horizontal recyclerview item width half of screen android 
Java :: android check file extension 
Java :: netbeans android sdk location 
Java :: java.lang.SecurityException: Permission Denial: reading androidx.core.content.FileProvider 
Java :: date java use fix timezone 
Java :: java set font 
Java :: difference between two sets java 
Java :: android studio find all views in layout 
Java :: copy text from header tag in javacript 
Java :: how to compare doubles in java 
Java :: double number java 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =