Search
 
SCRIPT & CODE EXAMPLE
 

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();
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: android java string animations 
Java :: detect bluetooth headphones android programmatically 
Java :: spring secutiry urls redirecting 
Java :: what is java.io example 
Java :: split by asterisk java 
Java :: internal hashcode 
Java :: android stop audio playing by activity lifecycle 
Java :: destroy fragent after navigating 
Java :: pack in swing 
Java :: error: package android.support.v4.content does not exist import android.support.v4.content.LocalBroadcastManager; 
Java :: Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0 
Java :: how to write a perfect shuffle method in java 
Java :: size of a tree node java linked;ist 
Java :: mysqld always running 
Java :: Performance data in appium 
Java :: Java HashMap Class Declaration 
Java :: Java Creating a LinkedHashMap 
Java :: java filewriter not working 
Java :: java konsoleneingabe 
Java :: convert java code to kotlin online editor 
Java :: isblank vs isempty java string utils 
Java :: Scanner library showing element not found exception 
Java :: path.resolve java 
Java :: java run multiple cmd commands 
Java :: dynamic fib 
Java :: what is a producedure java 
Java :: number output swing java 
Java :: int to byte calculator 
Java :: implicit type casting in java 
Java :: android paint drawtext multiline 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =