What is the output of the following code snippet?class Parent { static void print() { System.out.println("Parent"); }}class Child extends Parent { static void print() { System.out.println("Child"); }}public class Main { public static void main(String[] args) { Parent obj = new Child(); obj.print(); }}Question 2Answera.Parentb.Childc.Runtime errord.Compilation error
Question
What is the output of the following code snippet?class Parent { static void print() { System.out.println("Parent"); }}class Child extends Parent { static void print() { System.out.println("Child"); }}public class Main { public static void main(String[] args) { Parent obj = new Child(); obj.print(); }}Question 2Answera.Parentb.Childc.Runtime errord.Compilation error
Solution
The output of the given code snippet will be "Parent".
Similar Questions
Output of following Java program?class Grandparent { public void Print() { System.out.println("Grandparent"); } } class Parent extends Grandparent { public void Print() { System.out.println("Parent"); }} class Main{ public static void DoPrint( Grandparent o ) { o.Print(); } public static void main(String[] args) { Grandparent a = new Grandparent(); Grandparent b = new Parent(); Parent c = new Parent(); DoPrint(a); DoPrint(b); DoPrint(c); }}OptionsGrandparentGrandparentParentGrandparentParentParentGrandparentParentGrandparentCompiler Error
What will be the output of the following code snippet?public class MyClass { static int value = 10; public void printValue() { System.out.println(value); } public static void main(String[] args) { MyClass obj = new MyClass(); obj.printValue(); }}Question 4Answera.0b.10c.Compilation errord.Runtime exception
Observe the below code :class Parent { public void display() { System.out.println("Parent"); }}class Child extends Parent { public void display() { System.out.println("Child"); }}public class Main { public static void main(String args[ ]) { Parent p = ; Child c = ; p.display(); c.display(); }}Fill the code accordingly, so that you get the output asChildChild.
What is the output of this program? class A { public int i; private int j; } class B extends A { void display() { super.j = super.i + 1; System.out.println(super.i + " " + super.j); } } class inheritance { public static void main(String args[]) { B obj = new B(); obj.i=1; obj.j=2; obj.display(); } }2 23 3Runtime ErrorCompilation Erro
What will be the output of the following Java program?class A { int i; void display() { System.out.println(i); }}class B extends A { int j; void display() { System.out.println(j); }}class inheritance_demo { public static void main(String args[]) { B obj = new B(); obj.i = 1; obj.j = 2; obj.display(); }}Options02Compilation Error1
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.