Document
Document
Class Degree {
Void getDegree() {
Void getDegree() {
System.out.println(“I am an Undergraduate”);
Void getDegree() {
System.out.println(“I am a Postgraduate”);
Degree.getDegree();
Undergrad.getDegree();
3rd question
Class Computer {
// Data members
Int wordSize;
Int memorySize;
Int storageSize;
Int speed;
// Default constructor
Public Computer() {
// Default values
wordSize = 32;
memorySize = 512;
storageSize = 256;
speed = 2000;
// Parameterized constructor
This.wordSize = wordSize;
This.memorySize = memorySize;
This.storageSize = storageSize;
This.speed = speed;
}
// Display function
Int length;
Int width;
Int height;
Int weight;
// Default constructor
Public Laptop() {
Length = 13;
Width = 8;
Height = 0;
Weight = 2;
// Parameterized constructor
Public Laptop(int wordSize, int memorySize, int storageSize, int speed,
This.length = length;
This.width = width;
This.height = height;
This.weight = weight;
@Override
// Example usage
Desktop.display();
System.out.println();
Laptop myLaptop = new Laptop(64, 1024, 512, 3000, 15, 10, 1, 4);
myLaptop.display();
4th question
Class PrintIntegerAndCharacter {
System.out.println(“Integer: “ + n);
System.out.println(“Character: “ + c);
System.out.println(“Character: “ + c);
System.out.println(“Integer: “ + n);
// Example usage
Printer.print(5, ‘A’);
System.out.println(); // Adding a line break for clarity
Printer.print(‘B’, 10);
5th question
Class Student {
// Data members
Public Student() {
This.name = “unknown”;
This.age = 0;
This.name = name;
This.age = age;
}
// Method to set name, age, and address
This.name = name;
This.age = age;
This.address = address;
System.out.println(“Name: “ + name);
System.out.println(“Age: “ + age);
System.out.println(“Address: “ + address);
System.out.println();
// Example usage
If (I % 2 == 0) {
Students[i].setInfo(“Student” + (I + 1), 20 + i);
} else {
Students[i].displayInfo();
6th question
Class Vehicle {
// Properties
String make;
String model;
Int year;
String fuelType;
// Constructor
This.make = make;
This.model = model;
This.year = year;
This.fuelType = fuelType;
}
// Method to calculate fuel efficiency (dummy implementation)
Return 20.0;
Return 120;
// Constructor
}
Class Car extends Vehicle {
// Constructor
// Constructor
// Example usage