BCA Slip5 Java

Java

Slip5

Q.1) Define a class Student with attributes rollno and name. Define default and parameterized constructor. Override the toString() method. Keep the count of Objects created. Create objects using parameterized constructor and Display the object count after each object is created. [Marks 30]

Solution

import java.io.*;
import java.util.*;
class student
{
int rno;
String name;
static int count=0;
student()
{
}
student(int a,String s)
{
rno=a;
name=s;
}
void display()
{
System.out.println("Rno="+rno);
System.out.println("Name="+name);
count++;
System.out.println("count="+count);
}
}
class slip5
{
public static void main(String args[])
{
student s1=new student(1,"aaa");
s1.display();
}
}
BCA Pratical Solution

My name is Vivek And I from Mumbai and Complete my Graduation Bca.my Age is 23 Years.

Post a Comment

Previous Post Next Post