Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Ppl home assignment_unit3


Published on

Published in: Technology, News & Politics
  • Be the first to comment

  • Be the first to like this

Ppl home assignment_unit3

  1. 1. 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, “” and “vit.cse.fe”- in “” 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
  2. 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