Answers for "Java program to print Student Info by using Class, Object, Method."

0

Java program to print Student Info by using Class, Object, Method.

class Student{
    String name;
    int age;

    public void printInfo(){
        System.out.println("This is my name: " + this.name);
        System.out.println("This is my age: " + this.age);
    }
}

public class OOP {
    public static void main(String[] args) {
        Student s1 = new Student();
        s1.name = "Syed Momin ALi";
        s1.age = 21;

        Student s2 = new Student(); // This is a new object
        s2.name = "Syed Khizar ALi"; 
        s2.age = 19; 

        s1.printInfo();
        s2.printInfo();
    }
}
Posted by: Guest on April-23-2022

Code answers related to "Java program to print Student Info by using Class, Object, Method."

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language