Tai assignments Flashcards
Create a class and instantiate it
class Student{
int rollno;
int age;
String name;
int grade;
char section;
String subjects[];
void displayDetails(){
System.out.println(“Roll no: “+rollno);
System.out.println(“Age: “+age);
System.out.println(“name: “+name);
System.out.println(“section: “+section);
System.out.println(“grade: “+grade);
for(String subject:subjects){
System.out.println(subject);
}
}
}
class Main{
public static void main(String[] args){
Student Student1 = new Student();
Student1.age = 12;
Student1.rollno = 23;
Student1.grade = 8;
Student1.section = ‘D’;
Student1.name = “Vaishnavi”;
Student1.subjects = new String[]{“math”, “Hindi”, “English”};
Student1.displayDetails();
}
}
Garbage Collection in Java
Garbage Collection in Java
Garbage collection is a mechanism in Java that automatically frees up memory occupied by objects that are no longer needed or referenced. This process is performed by the Java Virtual Machine (JVM) to prevent memory leaks and ensure efficient use of system resources. The JVM periodically identifies objects that are no longer in use and reclaims their memory, making it available for new object allocations. Garbage collection is a crucial aspect of Java programming, as it eliminates the need for manual memory management and reduces the risk of memory-related errors.
create an interface
using recursion write code to find factorial of a number
access modifiers accessed using getters and setters
return object
Static variable static method and static block ? can static variable be access by non static method and why?
what is the use of static method