In: Computer Science
Please, i need Unique answer, Use your own words (don't copy and paste).
*Please, don't use handwriting.
Please, i need Unique answer, Use your own words (don't copy and paste).
*Please, don't use handwriting.
Q1: Assume that there is a class named TestInterface that implements two interfaces A and B. Both the interfaces have a common method with the same signature (example int sampleMethod()). Explain how will the class define this method and how will the compiler identify, to which interface does this method belong to? Will the compiler give an error or will the program execute successfully. Give your code snippet to support your answer.
Please, i need Unique answer, Use your own words (don't copy and paste).
*Please, don't use handwriting.
Please, i need Unique answer, Use your own words (don't copy and paste).
*Please, don't use handwriting.
_______________________________________________
Q4:
b.
class Parent
{
public void getBike()
{
System.out.println("Suzuki Bike");
}
}
class Child extends Parent
{
public void getCar()
{
System.out.println("Swift car");
}
}
class inheritance
{
public static void main(String args[])
{
Parent p = new Parent();
p.getBike();
Child c = new Child();
c.getBike();
c.getCar();
}
}
Please, i need Unique answer, Use your own words (don't copy and paste).
*Please, don't use handwriting.
Please, i need Unique answer, Use your own words (don't copy and paste).
*Please, don't use handwriting.
Q.1
Solution for the above:
public class HelloWorld {
public static void main(String[]args){
TestClass test=new TestClass();
test.diplay();
}
}
interface TestInterface{
void display();
}
interface|1 extends TestInterface{
@Override
void display();
}
interface|2 extends TestInterface{
}
class TestClass implements|1,|2{
@Override
pulic void display(){
sytem.out.printIn('Yes");
}
}
so this is the code given according to the problem.
-first interface i have overrriden the class but in other i have not done.
-make sure that if an interface extends another interface it is not required to override the methods.
-the methods are overrriden in all the interface. complier will not give error.
now, lets see the code for the requirement:
public class HellowWorld{
public static void main(string[]args){
TestClass test=new TestClass();
test.display();
}
}
interface TestInterface{
void display();
}
interface|1extends TestInterface{
@overrride
void display();
}
interface|2 extends TestInterface{
@override
void display();
}
class TestClass implements |1,|2{
@overrride
public void display(){system.out.printIn("Yes");
}
}