Quiz Space

Java OPPE 1: September 2023 (September 2023 term)

Question 1

+25 marksProgramming

In a college, Student s1 chooses a set of courses. Student s2 also chooses all the courses chosen by s1 except the second course, in place of which s2 chooses another course. Write a program that defines two classes Student and Admission. Define a copy constructor to create s2 from s1 such that changing the values of instance variables of either s2 or s1 does not affect the other one. The code takes the name of student s2 and the new course chosen by s2 as input.

  • Class Student has/should have the following members.
    • Private instance variables String name and String[] courses to store the name and the courses chosen, respectively
    • Define the required constructor(s)
    • Accessor methods getName() and getCourses(int) to get the name of the student and the course at a specific index, respectively.
    • Mutator methods setName(String) and setCourses(int, String) to set the name of the student and the course at a specific index, respectively.
  • Class Admission has method main that does the following.
    • Two objects of Student, s1 and s2, are created. s2 is created using s1.
    • The name of Student s2 and the second course chosen by s2 are updated by taking the input.
    • Finally, the names of s1 and s2 and the second course chosen by s1 and s2 are printed.

What you have to do:

  • Define constructor(s) in class Student

Question 2

+25 marksProgramming

Complete the Java program to demonstrate the use of abstract classes and interfaces. You have to complete the definition of classes JuniorRS and SeniorRS to obtain the output as given in the public test cases.

  • Interface IResearchScholar has two methods: public void teaches(String str) and public void studies(String str).
  • Define classes JuniorRS and SeniorRS such that JuniorRS implements IResearchScholar and SeniorRS extends JuniorRS.
  • Class InterAbstrTest extends SeniorRS, and has the main method. An object of JuniorRS invokes the method studies, and an object of SeniorRS invokes the methods studies and teaches.

Question 3

+25 marksProgramming

Complete the Java code that uses the concept of inheritance to demonstrate dynamic method dispatching.

  • Class Vehicle has the following members:
    • Private instance variable name
    • Constructor to initialize name
    • Accessor method for name
    • Method display to display the text: This is a generic vehicle.

Classes Car and Bicycle should be defined in such a way that any object of Car or Bicycle can be assigned to a reference variable of type Vehicle. See the main method to understand the context.

  • For Car, the method display should print: This is a car named <name>.
  • For Bicycle, the method display should print: This is a bicycle named <name>.

In the main method of the DispatchExample class, an array of Vehicle objects of size 3 is created.

  • The first element is a generic vehicle (with an empty string for its name).
  • The second and third elements are a Car and a Bicycle, respectively, with the vehicle's name taken as input.
  • It iterates over the array and calls the display method for each vehicle.

What you have to do:

  • Define an accessor method for name and method display inside class Vehicle
  • Define classes Car and Bicycle

5 more questions in this paper

Sign in with Google — it is free — to see every question with its answer and explanation, practise it in learning mode, or take it as a timed mock test.

More on the Java OPPE 1 Sept 2023 paper

The IIT Madras BS Programming Concepts using Java (Java) OPPE 1 paper sat on Sept 2023, in the September 2023 term (T3 2023): 8 questions for 200 marks in 180 minutes. The first 3 questions are below. Sign in with Google — it is free — to see the whole paper with its answers and explanations, in learning mode or as a timed mock test.

FeatureJava OPPE 1 Sept 2023 at a glance
TermSeptember 2023 term (T3 2023)
SubjectProgramming Concepts using Java
Course codeBSCS2005
Questions8
Marks200
Duration180 min
Programming8
Official paperOPPE 1, Sep 2023
Negative markingNo negative marking.
Updated

Same OPPE 1, other subjects

More Java