This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class FinalMethodExample | |
| { | |
| public final void display() | |
| {System.out.println("We are implementing Final method example");} | |
| public static void main(String args[]) | |
| {new FinalMethodExample().display();} | |
| class Sample extends FinalMethodExample | |
| { | |
| public void display() | |
| {System.out.println("hi");} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Demo | |
| { | |
| final int MAX_VALUE=99; | |
| void myMethod() | |
| { | |
| MAX_VALUE=101; | |
| } | |
| public static void main(String args[]) | |
| { | |
| Demo obj=new Demo(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class TestAbstraction1 | |
| { | |
| public static void main(String args[]) | |
| { | |
| try | |
| { | |
| System.out.println("First statement of try block"); | |
| int num=45/3; | |
| System.out.println(num); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| abstract class Shape | |
| { | |
| abstract void draw(); | |
| } | |
| class Rectangle extends Shape | |
| { | |
| void draw(){System.out.println("drawing rectangle");} | |
| } | |
| class Circle1 extends Shape | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Generate Output / Error (if any) for the following code. Justify your answer. | |
| class Main | |
| { | |
| public static void main(String[] args) | |
| { | |
| // create a final variable | |
| final int AGE = 32; | |
| AGE = 45; // try to change the final variable | |
| System.out.println("Age: " + AGE); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (Abstract class) Define an abstract class Animal with three data members viz. vegetarian (boolean), | |
| runningSpeed (int), animalName (String). The class Animal should have a constructor with three arguments | |
| which are assigned to the data members mentioned above. The class Animal should also have an abstract | |
| method display(). Now, inherit two classes Carnivorous and Vegetarian from Animal and write appropriate | |
| constructor and the display method. In the main method, create an object Lion of class Carnivorous and Cow of | |
| class Vegetarian with appropriate data members. The Lion and the Cow object should call the display() | |
| function to print appropriate messages. | |
| abstract class Animal | |
| { | |
| boolean vegetarian; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 4.1 (Final method) Define a class Result with dbms, os and java as data members. Write a constructor with three | |
| arguments that initializes the three data members with these three arguments. Define a final method | |
| calculate() that returns the total of all the three subjects. In the main method, create an object of class Result | |
| and invoke the method calculate(). | |
| class result | |
| { | |
| int dbms, java, os, total; | |
| result (int a, int b, int c) | |
| { | |
| dbms=a; java=b; os=c; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Consider a scenario where Bank is a class that provides functionality to get the rate of interest. | |
| However, the rate of interest varies according to banks. | |
| For example, SBI, ICICI and AXIS banks could provide 7%, 7.5%, and 7.75%. | |
| Write a Java Program to demonstrate the real scenario of Java Method Overriding where three classes (SBI, ICICI and AXIS) are overriding the method of a parent class (Bank) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Create a superclass Animal that has a method called animalSound(). | |
| Subclasses of Animal could be Pig, Cat, and Dog. And they also have their own implementation of an animal sound (e.g.: the pig oinks, and the cat meows, dog barks etc.) | |
| Now create objects of Pig and Dog objects and call the animalSound() method on both of them. [Inheritance and method overriding] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Define a class Doctor with Name as data member. | |
| Inherit a class Surgeon from the Doctor class with an extra data member Specialization and Consulting Charge per hour. | |
| Inherit another class Physician with an extra members Speciality and Fees per hour. | |
| Define objects S1 (Specialization= Gynaecologist, Fees per hour= Rs. 2000) and S2(Specialization= Paediatrician, Fees per hour= Rs. 1500). | |
| Define objects P1 (Speciality=Heart, Consulting Charge per hour= Rs. 4000) and P2(Speciality=Orthopaedic, Consulting Charge per hour = Rs. 2500). | |
| Write a main method to create objects as mentioned and required methods to read/display the information. | |
| NOTE: Sub-class must call super class constructor. |