0% found this document useful (0 votes)
2 views2 pages

Java Method Overloading and Inheritance Guide

The document contains multiple choice questions and answers related to Java programming concepts such as method overloading, type casting, and inheritance. It also includes output generation examples, short questions on key topics, error finding scenarios, and code writing tasks for various Java classes. Overall, it serves as a comprehensive overview of fundamental Java programming principles and practices.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Java Method Overloading and Inheritance Guide

The document contains multiple choice questions and answers related to Java programming concepts such as method overloading, type casting, and inheritance. It also includes output generation examples, short questions on key topics, error finding scenarios, and code writing tasks for various Java classes. Overall, it serves as a comprehensive overview of fundamental Java programming principles and practices.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1.

Multiple Choice Questions (MCQ)


Q1. Which of the following is NOT a valid way of method overloading in Java?
Answer: Changing the return type only.
Q2. What will happen in 'double d=9.8; int i=(int)d;'? Answer: i=9
Q3. Which type promotion is correct? Answer: long → float
Q4. Arrays in Java are: Answer: Objects
Q5. Default value of int[] elements: Answer: 0
Q6. Keyword for inheritance: Answer: extends
Q7. Subclass cannot access private superclass members directly.
Q8. Method overriding: Same method signature in subclass & superclass.
Q9. Use of super keyword: to call parent constructor, method, variable.
Q10. Java does not support multiple inheritance with classes.

2. Output Generation
Casting example → 5
Method overloading add(5,10) and add(5.5,4.5) → 15 and 10.0
Array {10,20,30,40} arr[2] → 30
Shape s=new Circle(2.0).calculateArea() → 12.566...
Bank b=new DBBL().getRateOfInterest() → 7.0

3. Short Questions
Q1. Type casting: converting one type into another.
Q2. Method overloading: same name, different params.
Q3. Method overriding: same signature, subclass, runtime polymorphism.
Q4. Primitive vs Reference: value vs address, fixed vs objects.
Q5. Rules of overriding: same name, params, inheritance relation.
Q6. super keyword: calls parent constructor, access hidden fields/methods.

4. Error Finding
Missing default constructor in Tulip → add Tulip(){}
Array out of bounds: arr[3] invalid in new int[3].
Private members not accessible → use getter/setter.
Return type mismatch in overriding → must match.

5. Code Writing
Adder class with overloaded add methods.
Find largest element in an array.
Tulip class with constructors, getters, setters.
Inheritance example: Shape→Circle with calculateArea().
Hierarchical inheritance: Shape→Circle, Rectangle overriding area().
Bank class with subclasses BRAC, DBBL overriding getRateOfInterest().

You might also like