Q) Consider the following code package com; public interface Training{ static void training(){ System.out.println("Gener
Posted: Thu Jul 14, 2022 2:18 pm
Q) Consider the following code
package com;
public interface Training{
static void training(){
System.out.println("Generic Training is going on..");
}
}
package com;
public class StreamTraining implements Training{
static void training(){
System.out.println("Stream training is going on");
}
}
package com;
public class JavaTraining extends StreamTraining implementsTraining{
static void training(){
System.out.println("Java Training is going on");
}
public static void main(String[] args){
Training training = new JavaTraining(); //line0
Training.training(); //line1
training.training(); //line2
}
}
what will be the output after execution? and why?
a) compilation error at line1 as training() functionshould be called with reference variable training created atline0
b) Compilation error at line 2 as training()function should be called with a static way andRunTimeException will be thrown after forceful execution
c) Compilation error in JavaTaning as it should first implementTraining interface then extend StreamTraining class
d) Generic Training is going on.. will be displayed on theconsole followed by a RunTimException at line2
package com;
public interface Training{
static void training(){
System.out.println("Generic Training is going on..");
}
}
package com;
public class StreamTraining implements Training{
static void training(){
System.out.println("Stream training is going on");
}
}
package com;
public class JavaTraining extends StreamTraining implementsTraining{
static void training(){
System.out.println("Java Training is going on");
}
public static void main(String[] args){
Training training = new JavaTraining(); //line0
Training.training(); //line1
training.training(); //line2
}
}
what will be the output after execution? and why?
a) compilation error at line1 as training() functionshould be called with reference variable training created atline0
b) Compilation error at line 2 as training()function should be called with a static way andRunTimeException will be thrown after forceful execution
c) Compilation error in JavaTaning as it should first implementTraining interface then extend StreamTraining class
d) Generic Training is going on.. will be displayed on theconsole followed by a RunTimException at line2