100% found this document useful (1 vote)
995 views3 pages

Midterm Practical Exam (OOP)

1. The document describes an object-oriented programming midterm exam with 8 questions. It provides code snippets as answers to questions about creating classes, constructors, accessors, and inheritance. 2. The questions cover topics like declaring constructors, overloaded constructors, accessor methods, inheritance between classes, and calling parent class constructors. 3. Code examples show creating classes like Exam, Midterm, and Essay that inherit from each other to demonstrate multiple levels of inheritance.

Uploaded by

Alden Dades
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
100% found this document useful (1 vote)
995 views3 pages

Midterm Practical Exam (OOP)

1. The document describes an object-oriented programming midterm exam with 8 questions. It provides code snippets as answers to questions about creating classes, constructors, accessors, and inheritance. 2. The questions cover topics like declaring constructors, overloaded constructors, accessor methods, inheritance between classes, and calling parent class constructors. 3. Code examples show creating classes like Exam, Midterm, and Essay that inherit from each other to demonstrate multiple levels of inheritance.

Uploaded by

Alden Dades
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/ 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