Midterm Practical Exam (OOP)

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Dades, Alden T.

BSIT311

Midterm Practical Exam


Object-Oriented Programming

1. Create a constructor named Exam that assigns "Good luck" to a previously


declared String variable named message.
class Exam {
private String message;
message = "Good luck";

2. Create an empty overloaded constructor for the Exam class with two (2) String
parameters named period and level.
public class Exam {
private String period;
private String level;
public class Exam() {
period = “No period yet”;
level = 0;
}
public class Exam(String period, String level) {
this.period = period;
this.level = level;
}
public class Exam(String period) {
this.period = period;
}
public class Exam(String level) {
this.level = level;
}
}

3. Declare a double-type accessor named getPrice that returns the value of price.
public double getPrice() {
price = 0;
return price;
}

4. Declare a boolean-type accessor named isFinished that returns the value of

1
status.
public class Test {
public static void main Status(String[] args) {
boolean isFinished = true;
}
return Status;
}

5. Declare a class named Midterm that inherits from the class named Exam.
class Midterm {
String Subject = Math;
Public void sub() {
}
}
class Exam extends Midterm {
private String sectionName = BSIT;
public static void main(String [] args) {
}
}

6. Create three (3) class declarations to show multiple levels of inheritance. Use the
classes named Exam, Midterm, and Essay.
public class Exam {
public int output;
}
public class Midterm extends Exam {
public int performanceTask;
}
public class Essay extends Midterm {
public int longQuiz;
}
public void main(String[] args) {
Exam exam = new Exam();
Midterm midterm = new Midterm();
Essay essay = new Essay();
}

7. Create a constructor named Midterm that prints "Exam has started." using
println(). Its first statement should be a call to a constructor in the parent class.
public class Main {
int x;
public Main {
x = “Exam has started”:
}
public class void main(String[] args) {
Main midterm = new Main();

2
System.out.println(Midterm.x);
}
}

8. Given the base class named Quiz and the derived class named Essay, write a
statement to show inheritance between these classes.
class Quiz {
String Subject = Math;
public void sub() {
}
}
class Essay extends Quiz {
private String longTest = firstYear;
public static void main(String [] args) {
}
}

You might also like