Example HTML page

java assignment 4

Hi, Please workout the following java assignments

1.Demonstrate the concept of simple inheritance by creating a superclass called A and a subclass called B. Notice how the keyword extends is used to create a subclass of A. Declare  superclass datamembers as i,j and subclass datamember as k. use method sum( ) to perform addition of i+j+k in the subclass. Show how to access all the datamembers and member functions from main( ).

2.Use the keyword ‘super’ and show how to use this ‘super’ keyword to call the superclass constructor as well as the same keyword usage to access the superclass datamembers too. Create two separate programs for each example.

3.Apply the concept of Multilevel hierarchy, represent 3 classes namely car (super class), maruti( subclass) & maruti800(another subclass) & show hoe the order in the derivartion from super class to its subclasses how their corresponding constructors are called.

4.Create any two classes of your wish and apply the concept of method overriding and declare data members, constructors & methods. Demonstrate how to override the method that exists in the subclass.

5.Create a abstract method callme( ) and also a concrete method callmetoo in the super class A. Create another class B and also create an object for it. From the main method without creating an object for A. Show the access for both the concrete and abstract methods.

6. Show how the keyword ‘final’ is used to prevent method overriding by considering any one method and also how it is used to prevent inheritance  for any class. Take any two separate programs and represents two concepta in each.

7.Create a simple package named ‘mypack’ , create a class Balance and declare name , bal as data members in it and display the name and bal of each employee. Exceptional case: if(bal<0) you should display the message as “Negative balance” and also the corresponding employee details.

8.Create ‘Myclass’ that implements an interface B which in turn extends from an interface A. Interface A contains meth1( ), meth2( ) as abstract methods & interface B contains meth3( ) as an abstract method. And show how ‘Myclass’ is going to implements those abstract methods.

9.Use the keywords try and catch of Exception handling mechanism. In the try block represent the exception as divided by 0, exceeding the array limit and raise an exception such as ArithmeticException and it should be caught in the  first catch block. In another catch block it should display the ArrayIndexOutOfBounds Exception. And also observe how these multicatch statements are going to be executed one at a time.

10.Use the keywords throw, throws and finally of exception handlig mechanism and show how to throw an exception using throw, throws keyword and also implement finally keyword to demonstrate that irrespective of any other words it’s going to be executed by default.

 

Example HTML page

Leave a Reply

Your email address will not be published. Required fields are marked *

Pin It on Pinterest