SampleQuestionPaper Compre
SampleQuestionPaper Compre
Note:
1. Please follow all the Instructions to Candidates given on the cover page of the answer book.
2. All parts of a question should be answered consecutively. Each answer should start from a fresh page.
3. Assumptions made if any, should be stated clearly at the beginning of your answer.
Write a Java program to create a class Numbers which has a method checkNumber
which takes an integer as input and checks if the number is prime or not and prints a
message “It’s a prime number” or “It’s not a prime number” accordingly. Create two
classes PrimeNumber and NonPrimeNumber both of which extends Thread and has
an object of type Number and implements the run method and calls he checkNumber()
method using the Number object. Define appropriate constructors for the defined
classes. Create the main class, create objects for the Number, PrimeNumber and
NonPrimeNumber classes and start the threads. Write the expected output of your
program for a given input.
Question 5 Set (A) (8 marks)
Write a Java program to create a class Student with name, id and gpa with required
constructors and a display method to display the student details. In the main class
create 5 instances of Student. Create an ArrayList stuList and add the 5 students. Use
the get() method of ArrayList to get the data from the stuList and check if they are
instances of the Student class. If they are instances of Student class then print their
details by calling the display() method.