click below
click below
Normal Size Small Size show me how
Java OOP
Question | Answer |
---|---|
John got a recipe for cookies from his mother, but john likes choco chips, so he altered the original cookie recipe, this is an example for? | Method Overriding |
Physics Department in Caltech got a new 3D printer, Sheldon used the printer for printing prototypes for his hadron collider. Howard used the printer to print his mini action figure. this is an example for? | Polymorphism |
public class Area{ main() { Area a= new Area(); System.out.println(a.calculateTriangleArea(1.0,2.0)); } public double calculateTriangleArea(double d, double e) { return 0.5*d*e; } } | 1.0 |
Apple launched a new iPhone named iPhone 14 with new features, and it has 3 models, iPhone 14 basic, iPhone 14 pro and iPhone 14 pro max and iPhone 14 mini, which implementation is better for this scenario? | A class iPhone 14 and inner class for each model. |
public class Main { public int i = 0; main() { Main m = new Main(); Main.Nested mn = m. new Nested(); mn.printVariable(10); } class Nested{ public int i = 2; void printVariable(int i) | 10 2 0 |
A DigitalThermometer needs to be configured only once and after that initial configuration, it'll detect the temperature perfectly. | DigitalThermometer class which inherits and overrides the methods of Configuration interface using an anonymous inner class. |
KIA launched 4 car models named seltos, carnival, Carens and sonnet with features like Front and Side Airbags, Highline Tyre Pressure Monitor, Hill assist control etc. from the 5th model KIA wants to add a new feature of autopilot and self-driving. | A KIA interface with all features as abstract methods except for the new feature( autopilot) which is a default method and all models as classes that implement Kia. |
interface Elevator{ int goUP(); int goDown(); final void stop(); } | Compile-time error |
interface Electrical{ void controlLight(); void controlAC(); } interface Mechnical{ void pullUp(); void pullDown(); } interface Elevator extends Electrical, Mechnical{ int goUP(); int goDown(); } | The concrete class that implements Elevator, must override all the methdos of all the interface. |
English language vocabulary is comprised of old germanic, French, and Latin words, this is an example for? | Hybrid Inheritance |
Harry potter's Invisibility clock was passed down to him by his father James and James potter got it from his father Henry potter, this is a clear example for? | Multilevel Inheritance |
public final class Car{ public static void main(String args[]){ Car c = new Car(); c.engine(); } public void engine(){ System.out.println(" I am a Diesel engine"); } } | I am a Diesel engine |
public final class Car{ public static void main(String args[]){ KIA k = new KIA(); k.engine(); } } class KIA extends Car{ } | Compile-time error |
interface Car{ // code } public class Audi implements Car{ public static void main(String[] args) { Car c = new Audi(); } // code } | Object for Class Audi is created and it's refrence is assigned to the Interface. |
private class Main{ // code } | Compile-time error |
public class Child extends Parent, Grandparent{ System.out.println("Success") } | Compile-time error |
public class Game { public static void main(String[] args) { Game g; g.playCricket(); } void playCricket() { System.out.println("I am a Batsman"); } } | Compile-time error |
A vending machine has different items and functions to take the cash and dispense the item, but all these occur internally and as an external user one can only access it using selection buttons. This is an example for? | Encapsulation |
abstract public class Audi implements Car{ public static void main(String[] args) { } @Override public void engine() { // code } } | No error |
What is wrong with this code? public class Question { public void doThing() { } public static void main(String[] args) { doThing(); } } | The doThing() method must be declared static to be used in main() |
______ is also called Compile time Polymorphism or Method overloading. | Static Polymorphism |
Which of the following is an example of static binding? | method overloading |
Can java be considered an absolute Object Oriented language? | false |
Child classes must have the same variable value as their parent class | false |
A class in Java can extend multiple parent classes | false Java does not support multiple inheritance |
Java supports multiple inheritance of classes | false |
A superclass is extended by a subclass and the subclass is extended by another subclass. This is called as _______. | Multilevel Inheritance |
In java, combining two or many types of inheritance is considered as _______ Inheritance. | Hybrid inheritance |
In java, a class can not extend more than one class. | true |
A child class inherits all the properties of parent class so the child class can be implicitly upcasted to parent. This is called as _______. | upcasting |
A parent class may or may not have all the properties of Child class, so parent class can be explicitly downcasted to Child class. This is called as _______. | downcasting |
A static method can not be overriden if a sub class has a method with the same name as the static method in super class, its considered as _______. | data hiding |
Inherited behaviors can be overridden in a subclass | true |
True or False: The relationship between a class and this members is a, HAS-A relationship | true |
True or False: Child classes must have the same variable values as their parent class | false |
True or False: If the class Car extends class Automobile, then an instance of Automobile can access Car methods | false |
What will be the result of this method, if we pass in a Bird object? public void whatIsThis(Animal a) { if (a instanceof Dog) System.out.println(“This is a Dog!”); else System.out.println(“I don’t know what this is!”); } | “I don’t know what this is” |
True or False: A class in Java can extend multiple parent classes | false |
The @Override annotation… | Tell the compiler that the method is intended to override a superclass method |
True or False: Inherited behaviors can be overridden in a subclass | true |
Which keyword is used to show inheritance in Java? | extends |