Java Questions - (Has 2 Parts). Based on each code, which answer out of the choices "A,B,C,D,E" is correct. Each question has one correct answer. Thank you. Part 1 - 5. In Java, inheritance uses __ relationship. A. is-a B. part-of C. has-a D. member-of E. None of the options Part 2 - 6. Given the following code, the output is __. class Apple { int x = 15; } class Banana extends Apple { int x = 25; } public class Sample { public static void main(String[] args) { Apple a1 = new Banana(); System.out.println(a1.x); } } A. Compiler error B. 25 C. 15 D. 0 E. None of the options
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
Java Questions - (Has 2 Parts). Based on each code, which answer out of the choices "A,B,C,D,E" is correct. Each question has one correct answer. Thank you.
Part 1 - 5. In Java, inheritance uses __ relationship.
A. is-a
B. part-of
C. has-a
D. member-of
E. None of the options
Part 2 - 6. Given the following code, the output is __.
class Apple { int x = 15; }
class Banana extends Apple { int x = 25; }
public class Sample {
public static void main(String[] args) {
Apple a1 = new Banana();
System.out.println(a1.x);
}
}
A. Compiler error
B. 25
C. 15
D. 0
E. None of the options
Step by step
Solved in 2 steps