Ce133 JT Lab 3
Ce133 JT Lab 3
import java.util.*;
class primeNumber{
int value;
primeNumber(int value){
this.value = value;
}
boolean isPrime() {
for(int i = 2 ; i<value ; i++) {
if(value % i == 0) {
return false;
}
}
return true;
}
}
Output:
2.Create two classes:
class Person
Derive a class Student from class Person.
import java.util.*;
class person{
String name;
int age;
person(){
System.out.println("this the default constructer for person");
}
person(String name , int age){
this.name = name;
this.age = age;
}
String getName() {
return name;
}
int age() {
return age;
}
void setName(String name) {
this.name = name;
}
void setAge(int age) {
this.age = age;
}
public String toString() {
String s = "Name: "+name + "Age: " + age;
return s;
}
}
class student extends person{
int rollno;
double marks[]= new double [5];
static int count;
static {
count = 0;
}
student() {
System.out.println("this a default constructer of student");
count++;
}
student(int rollno){
this.rollno = rollno;
count++;
}
student(int rollno , double marks[]){
this.rollno = rollno;
this.marks = marks;
count++;
}
student(int rollno, String name , int age , double marks[]){
super(name,age);
this.rollno = rollno;
this.marks = marks;
count++;
}
int getRollNo() {
return rollno;
}
double[] getMarks() {
return marks;
}
Output: