/*Newly added tags for bing*/ Unipune Codes: Define Class, Create Objects using Parameterized Constructor and Display the Object Count after each Object

Pages

Friday, 12 June 2020

Define Class, Create Objects using Parameterized Constructor and Display the Object Count after each Object

 
       

class Student
{
 int roll;
 double per;
 static int cnt=0;
 student () {cnt ++}
 student (int r, String nm, double p)
 {
  roll = r;
  name=nm;
  cnt++;
  System.out.println("Counter= "+cnt);
 }
 public String toString()
 {
  return("Roll no "+roll+" Name= "+name+" Percentage= "+per);
 }
 public static void main(String args[])
 {
  Student s1= new Student (1,"Rohit",65.12);
  System.out.println(s1);
  Student s2= new Student (2,"Pranav",61.12);
  System.out.println(s2);
  Student s1= new Student (1,"Aditya",68.12);
  System.out.println(s1);
  System.out.println("Number of students: "+cnt);
 }
}


No comments:

Post a Comment