ect the correct answerIf the code executes fine then predict the correct output otherwise choose the suitable option.class Code { public void showTime() { System.out.println("657"); }} class Tantra extends Code { public void showTime() { System.out.println("-405"); }} public class Main { public static void main(String[] args) { Code b = new Tantra(); b.showTime(); }}Options657657-405-405error: showTime() in Tantra cannot override showTime() in Code-405657
Question
ect the correct answerIf the code executes fine then predict the correct output otherwise choose the suitable option.class Code { public void showTime() { System.out.println("657"); }} class Tantra extends Code { public void showTime() { System.out.println("-405"); }} public class Main { public static void main(String[] args) { Code b = new Tantra(); b.showTime(); }}Options657657-405-405error: showTime() in Tantra cannot override showTime() in Code-405657
Solution
The correct output will be "-405". This is because we have created an object of class Tantra but with reference of class Code. So, when we call the method showTime(), it will call the method from Tantra class. This is a concept of method overriding in Java.
Similar Questions
he correct answerAssuming that all the necessary imports are done, predict the output of the given Java Program. class Code { public Code(String s) { System.out.print("Code"); } } public class Tantra extends Code { public Tantra(String s) { System.out.print("Tantra"); } public static void main(String[] args) { new Tantra("Company"); System.out.println(" "); } }OptionsCodeCodeTantraCompanyTantraCompilation fails
Select the correct answerDecode the code and choose the correct results: abstract class A { final void showTime() { System.out.println("3900"); } } class B extends A { static void funTime() { System.out.println("7766"); } } public class Main { public static void main(String args[]) { A object = new B(); object.showTime(); B.funTime(); } }Options7766390077667766Error3900390039007766
Select the correct answerWhat will be the output of the following Java code?class Code{ Code()throws IOException { } }class Tantra extends Code{ Tantra() { } public static void main(String[]args) { }}Optionscompile and runs finerun time errorcompile time errorunreported exception java.io.IOException in default constructor
Select the correct answerWhat will be the output of the following Java code? class newthread extends Thread { Thread t; newthread() { t = new Thread(this,"New Thread"); t.start(); } public void run() { System.out.println(t.isAlive()); } } class Code_Tantra { public static void main(String args[]) { new newthread(); } }Optionstrue10false
Select the correct answerWhat will be the output of the following Java code? class overload { int Code; int Tantra; void add(int x) { Code = x + 1; } void add(int x, int y) { Code = x + 2; } } class Overload_methods { public static void main(String args[]) { overload obj = new overload(); int Code = 0; obj.add(6); System.out.println(obj.Code); } }Options7658
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.