Skip to content

Instantly share code, notes, and snippets.

View Liyansu's full-sized avatar
🏠
Working from home

Liyansu

🏠
Working from home
View GitHub Profile
@Liyansu
Liyansu / FinalMethodExample.java
Created June 5, 2021 16:47
5.1.5. Generate the output of the following code. Give supporting arguments/ reasons for your Output / Error (if any).
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");}
@Liyansu
Liyansu / Main.java
Last active June 5, 2021 16:44
5.1.4. Generate the output of the following code. Give supporting arguments/ reasons for your Output / Error (if any).
class Demo
{
final int MAX_VALUE=99;
void myMethod()
{
MAX_VALUE=101;
}
public static void main(String args[])
{
Demo obj=new Demo();
@Liyansu
Liyansu / TestAbstraction1.java
Last active June 5, 2021 16:41
5.1.3. What will be the correct sequence of the Output / Error (if any) for the following code
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);
}
@Liyansu
Liyansu / TestAbstraction1.java
Created June 5, 2021 16:34
5.1.2. Generate Output / Error (if any) for the following code
abstract class Shape
{
abstract void draw();
}
class Rectangle extends Shape
{
void draw(){System.out.println("drawing rectangle");}
}
class Circle1 extends Shape
{
@Liyansu
Liyansu / 5.1.1. Que.txt
Created June 5, 2021 16:23
5.1.1. Generate Output / Error (if any) for the following code. Justify your answer.
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);
}
@Liyansu
Liyansu / 4.2 Que.txt
Last active June 11, 2021 04:51
4.2 Define an abstract class Animal with three data members viz
(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;
@Liyansu
Liyansu / 4.1 Que.txt
Created June 5, 2021 16:14
4.1 (Final method) Define a class Result with dbms, os and java as data members
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;
@Liyansu
Liyansu / 3.3 Que.txt
Created June 5, 2021 16:03
3.3 Consider a scenario where Bank is a class that provides functionality to get the rate of interest.
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)
@Liyansu
Liyansu / 3.2 Que.txt
Created June 5, 2021 15:53
3.2 Create a superclass Animal that has a method called animalSound().
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]
@Liyansu
Liyansu / 3.1 Que.txt
Last active June 9, 2021 17:40
3.1 Define a class Doctor with Name as data member.
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.