• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Ppl home assignment_unit3

Ppl home assignment_unit3






Total Views
Views on SlideShare
Embed Views



0 Embeds 0

No embeds


Upload Details

Uploaded via as Microsoft Word

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

    Ppl home assignment_unit3 Ppl home assignment_unit3 Document Transcript

    • Bansilal Ramnath Agarwal Charitable Trust’s Vishwakarma Institute of Technology, Pune. 37 Principles of Programming Languages CS 20105 – SE – E Home Assignment 3Assignment Date: 15th March 2012 Submission Date: 20th March 2012Answer all 8 questions:1. Write a complete Java code to print “Home Assignment 3” on console.Specifically mention the file name and extension and the steps to compile andexecute your code.2. What will be the output of the following code?//Room.javapublic class Room { int i; public Room(int i) { this.i = i; } public void print() { System.out.println(i); }}//TestRoom.javapublic class TestRoom { public static void main(String[] args) { Room r = new Room(); r.print(); }}3. Look at the following organization of classes:- there are two packages, “vit.cse.se” and “vit.cse.fe”- in “vit.cse.se” there are two classes, A and B- in “vit.cse.fe” there are two classes, C and D- class A has - a private field: private int i; Page 1 of 2
    • - another field: int j; - a protected field: protected int k; - a public field: public int m;- class D extends class ABased on the above description, which of the following statements are true inJava: a) Any method defined in class A can access any of the fields i, j, k and m b) Any method defined in class A can access any of the fields j, k and m but not i since i is private c) Any method in class C can access m, k and j of A d) Any method in class B can access m and j in A e) Any method in class D can only access m of A since that is the only public field in A4. Write complete Java code for the following classes:- class Vehicle- class TwoWheeler- class FourWheeler- class Scooter- class CarUse inheritance and/or composition wherever appropriate. For fields andmethods, use common sense and make whatever assumptions necessary. Alsomention what are the different types of inheritance you have used in thisexample.5. Explain the signature of “main”method in Java.6. True or Falsea) Java supports multiple inheritanceb) Abstract class can contain some method implementationsc) Interface can be instantiatedd) A class can “extend” multiple classese) A class can “implement” multiple interfaces7. What is a “user defined exception”? Write Java code for defining a user-defined exception and a demo code for throwing and catching your exception.8. Give an example each of multi-level inheritance and hierarchical inheritance. Page 2 of 2