Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

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();
    }
}
Source by 127.0.0.1 #
 
PREVIOUS NEXT
Tagged: #Java #program #print #Student #Info
ADD COMMENT
Topic
Name
1+5 =