Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

B.

Tech CSC – IV Sem


Quiz II(19/02/19)
Time: 30 min. Marks:10 (Weightage:2.5)
Name: LMS Id No:
Instructions:
- Attempt the answer on the given sheet
Q1. What will be the output of the following code,if there is an error,specify the reason for the error:[6]

(a) class Demo (b) class Main{


{ int r; 1. int a=40;
Demo(int r1) 2. public static void main(String args[]){
{ r = r1; } 3. System.out.println(a);
void disp()
{System.out.println("Hello");} 4. }
public static void main(String args[]) 5. }
{ Demo ob = new Demo();
ob.disp(); } }

(c) class Demo{ (d) class A{


static{System.out.println("HELLO");} private int data=40;
public static void main(String args[]){ void msg()
System.out.println("Hello "); {System.out.println("Hello java");} }
} } public class Test{
public static void main(String args[]){
A ob=new A();
System.out.println(ob.data);
ob.msg(); } }

(e) class Demo{ (f) class Addition {


void disp(int a, double b){ public int add(int a, int b)
System.out.println("Hello"); } { int sum = a+b;
void disp(int a, double b, double c){ return sum; }
public double add(int a, int b)
System.out.println("HELLO");
{ double sum = a+b;
} return sum;
public static void main(String args[]){ } }
Demo obj = new Demo(); class Test
obj.disp(100, 20.67f); { public static void main (String[] args) {
} Addition ob = new Addition();
} int sum1 = ob.add(1,2);
System.out.println(sum1);
int sum2 = ob.add(1,2);
System.out.println(sum2);
}}

Q2. What is method overloading? What is the advantage of it? Also discuss different ways to implement
method overloading with the help of an example. [4]

You might also like