0% found this document useful (0 votes)
6 views19 pages

Output

The document outlines multiple Java programs demonstrating the implementation of a student class with varying access specifiers. It includes algorithms and source code for classes with default access, private access, and methods for data handling. Each program is executed successfully, with outputs verified.

Uploaded by

jasmineflora2006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views19 pages

Output

The document outlines multiple Java programs demonstrating the implementation of a student class with varying access specifiers. It includes algorithms and source code for classes with default access, private access, and methods for data handling. Each program is executed successfully, with outputs verified.

Uploaded by

jasmineflora2006
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 19

OUTPUT:

RESULT:
Thus the constructors and destructors program executed and verified successfully.
OUTPUT:

RESULT:
Thus the constructors and destructors program executed and verified successfully.
OUTPUT:

RESULT:
Thus the function overloading program executed and verified successfully.
OUTPUT:

RESULT:
Thus the program to implement hybrid inheritance executed and verified successfully.
OUTPUT:

RESULT:
Thus the program to implement multiple inheritance executed and verified successfully.
OUTPUT:

RESULT:
Thus the use of abstract class program executed and verified successfully
OUTPUT:

RESULT;
Thus the type conversion program executed and verified successfully.
AIM:
To write a Java program to implement a simple student class without access specifiers.

ALGORITHM:
1. Start the program.
2. Create a class Student with two data members with default access specifier.
3. Create another class named J2aSimpleClass
4. Create an object of type student inside the main() of J2aSimpleClass.
5. Assign values to the data members of student class inside the J2aSimpleClass.
6. Print the two data members of student class.
7. Stop the program
SOURCE CODE:
class student {
int regno;
String name;
}

public class J2aSimpleClass {


public static void main(String args[]) {
// Object Creation For Class
student s = new student();
s.regno = 100;
s.name = "John Marshal";

System.out.println("Reg No " + s.regno);


System.out.println("Name " + s.name);
}
}
OUTPUT:

RESULT:
Thus the Java program to implement a simple student class without access specifiers have
been completed successfully and the output is verified.
AIM:
To write a Java program to implement a simple student class with access specifiers.
ALGORITHM:
1. Start the program.
2. Create a class Student with two data members with private access specifier.
3. Create two methods to get values for data members and to display the data member
values
4. Create an object of type student inside the main() of J2bSimpleClass.
5. Assign values to the data members of student class through getdata() function.
6. Print the two data members of student class using showdata() funtion.
7. Stop the program
SOURCE CODE:
class student {
private int regno;
private String name;

void getdata() {
Scanner in = new Scanner(System.in);
System.out.println("Enter the Register Number");
regno = in.nextInt();
System.out.println("Enter the Name");
name = in.next();
}

void showdata() {
System.out.println("Reg No " + regno);
System.out.println("Name " + name);
}
}

public class J2bSimpleClass {


public static void main(String args[]) {
student s = new student();
s.getdata();
s.showdata();

// s.regno = 10; // ERROR: regno is private


}
}
OUTPUT:

RESULT:
Thus the Java program to implement a simple student class with access specifiers have been
completed successfully and the output is verified.
AIM:
To write a Java program to implement a simple student class with access specifiers.
ALGORITHM:
1. Start the program.
2. Create a class student with its data member and member function
3. Get marks and regno as Integer data type and name as String data type from user using
getdata().
4. Calculate the result in calculation().
5. Display Student details using show() function.
6. Create a main class J2cSimpleClass and create instances of student class
7. Using the instance call the above mentioned methods and find out whether the result of an
student is PASS or FAIL.
8. Stop the program
SOURCE CODE:
import java.util.Scanner;

class student {
private String name, result;
private int regno, m1, m2, m3, total;
private float percentage;

void getdata() {
Scanner in = new Scanner(System.in);

System.out.println("Enter the Register Number:");


while (!in.hasNextInt()) {
System.out.println("Invalid input. Please enter a number:");
in.next(); // Clear invalid input
}
regno = in.nextInt();

System.out.println("Enter the Name:");


name = in.next();

System.out.println("Enter mark1:");
while (!in.hasNextInt()) {
System.out.println("Invalid input. Please enter a number:");
in.next();
}
m1 = in.nextInt();

System.out.println("Enter mark2:");
while (!in.hasNextInt()) {
System.out.println("Invalid input. Please enter a number:");
in.next();
}
m2 = in.nextInt();

System.out.println("Enter mark3:");
while (!in.hasNextInt()) {
System.out.println("Invalid input. Please enter a number:");
in.next();
}
m3 = in.nextInt();
}

void calculation() {
total = m1 + m2 + m3;
percentage = total / 3.0f;

if (m1 >= 50 && m2 >= 50 && m3 >= 50) {


result = "PASS";
} else {
result = "FAIL";
}
}

void show() {
System.out.println("\n\t\t\tStudent Details");
System.out.println("Name = " + name);
System.out.println("Register Number = " + regno);
System.out.println("Marks of 1st Subject = " + m1);
System.out.println("Marks of 2nd Subject = " + m2);
System.out.println("Marks of 3rd Subject = " + m3);
System.out.println("Total Marks = " + total);
System.out.println("Percentage = " + percentage + "%");
System.out.println("Result = " + result);
}
}

public class jas {


public static void main(String[] args) {
student s = new student();
System.out.println("\t\t\tStudent Information System");
s.getdata();
s.calculation();
s.show();
}
}
OUTPUT:

RESULT:
Thus the Java program to implement a simple student class with access specifiers have been
completed successfully and the output is verified.

You might also like