Web viewIn what order are the constructors for these classes called when a Gamma object is...

2
Kantipur College of Management and Information Technology Preliminary Examination 2015 BIM/Third Semester/IT 216: Java Programming - I Candidates are required to give their answer in their own words as far as practicable Group A Brief Answer Questions: [10 × 1 = 10] i. Show how this sequence can be rewritten using the ? operator. if(x < 0) y = 10; else y = 20; ii. Why is final used with inheritance? iii. What is the use of values( ) and value Of( ) methods? iv. Given the following hierarchy: class Alpha { … } class Beta extends Alpha { …} class Gamma extends Alpha { …} In what order are the constructors for these classes called when a Gamma object is instantiated? v. What standard Java package is automatically imported into a program? vi. Differentiate between checked and unchecked Exceptions. vii. Why is synchronization of threads required? viii. For which purpose Serialization process is used? ix. Why is bytecode regarded as Java’s magic? x. Why is it sometimes advantageous to declare a variable as static? Group B Short Answer Questions: [5 × 4 = 20] i. When are methods said to be overloaded? Write a program to show an overloaded varargs method that is ambiguous. Full Marks: 40 Time: 2 hrs

Transcript of Web viewIn what order are the constructors for these classes called when a Gamma object is...

Page 1: Web viewIn what order are the constructors for these classes called when a Gamma object is instantiated?

Kantipur College of Management and Information Technology Preliminary Examination

2015

BIM/Third Semester/IT 216: Java Programming - I

Candidates are required to give their answer in their own words as far as practicable

Group ABrief Answer Questions: [10 × 1 = 10]

i. Show how this sequence can be rewritten using the ? operator. if(x < 0) y = 10; else y = 20;

ii. Why is final used with inheritance?iii. What is the use of values( ) and value Of( ) methods?iv. Given the following hierarchy:

class Alpha { … } class Beta extends Alpha { …} class Gamma extends Alpha { …}In what order are the constructors for these classes called when a Gamma object is instantiated?

v. What standard Java package is automatically imported into a program?vi. Differentiate between checked and unchecked Exceptions.vii. Why is synchronization of threads required?viii. For which purpose Serialization process is used?ix. Why is bytecode regarded as Java’s magic?x. Why is it sometimes advantageous to declare a variable as static?

Group BShort Answer Questions: [5 × 4 = 20]

i. When are methods said to be overloaded? Write a program to show an overloaded varargs method that is ambiguous.

ii. Write a program that displays all the files with .html extension of a given folder.iii. Why overridden methods? Imagine a publishing company that market both book and

audiocassette version of its work. Create a class Publication that stores the title(a String) and price(type double) of a publication. From this class derive two classes: Book, which adds a pagecount(type int), and Tape, which adds a playing time(type double). Each of these three classes should have their own constructors and also have show () method to display the data. Write a program to display the data of Book and Tape classes by creating instance of them.

iv. Make a class named Book with private member variables title, author, pubdate and public functions to set, display and return values of member variables. Then create five objects of the Book class, set them and display the names of books written by same

Full Marks: 40Time: 2 hrs

Page 2: Web viewIn what order are the constructors for these classes called when a Gamma object is instantiated?

author in the main function of another class named BookDemo.(Assume that same writer have written more than one books).

v. Give the ways of creating thread. Write a program, which creates three threads. One thread display the numbers from 1 to 5, second thread display the square of that numbers and third thread display the cube of that numbers. Set the priority of each thread so the number thread run first, square thread run second and cube thread run last.

Group CLong Answer Questions: [2 × 5 = 10]

i. “The use of package is naming and visibility control mechanism in java”. Support the statement with an example.

ii. Explain how it is advantageous to catch superclass exceptions with an appropriate example. Illustrate the user defined exception with an example.