Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1. What will happen when you compile and run the following code? class One{ public static void process(){ System.out.print(Parent); } } class Two extends One{
1. What will happen when you compile and run the following code? class One{ public static void process(){ System.out.print("Parent"); } } class Two extends One{ public static void process(){ super.process(); System.out.print("Child"); } } public class Test{ public static void main(String args[]){ One one = new Two(); one.process(); } }
a. Parent
b. Compilation Error
c. Child
d. ParentChild
2.
Given the code fragment, what will be the output when you compile and run the code.
class One{ String className = "One"; } class Two extends One{ String className = "Two"; } public class Test{ public static void main(String[] args) { One one = new Two(); System.out.println(one.className); } }
a. Compilation error
b. Two
c. Runtime error
d. One
3.
What will happen when you compile and run the following code?
class One{ public abstract One(); } class Two extends One{ public Two(){ System.out.println("Two"); } } public class Test{ public static void main(String[] args) { Two two = new Two(); } }
a. Compilation error
b. Runtime error
c. Two
4.
What will happen when you compile and run the following code?
public class Test{ public void doNothing(Object object){ System.out.println("Object"); } public void doNothing(Integer i){ System.out.println("Integer"); } public void doNothing(Double i){ System.out.println("Integer"); } public static void main(String[] args) { Test test = new Test(); test.doNothing(args); } }
a. Double
b. Integer
c. None of the above
d. Object
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started