SlideShare a Scribd company logo
Inheritance
Duration : 30 mins.
Q1 .Consider the following code:
class Base
{
        private float f = 1.0f;
        protected void setF(float f1){ this.f = f1; }
}
class Base2 extends Base
{
        private float f = 2.0f;
        //1
}

Which of the following options is a valid example of overriding?

Select 2 correct options
a protected void setF(float f1){ this.f = 2*f1; }
b public void setF(double f1){ this.f = (float) 2*f1; }
c public void setF(float f1){ this.f = 2*f1; }
d private void setF(float f1){ this.f = 2*f1; }
e float setF(float f1){ this.f = 2*f1; return f;}

Ans: a,c
Q2
You are modeling a class hierarchy for living things.
You have a class LivingThing which has an abstract method reproduce().
Now, you want to have 2 subclasses of LivingThing, Plant and Animal.
Obviously, both do reproduce but the mechanisms are different.
What would you do?

Select 1 correct option.
a Overload the reproduce method in Plant and Animal Clases
b Overload the reproduce method in LivingThing Class.
c Override the reproduce method in Plant and Animal Clases
d Either overload or override, it depends on the taste of the designer.




Ans: c
Q3
An abstract method cannot be overridden.

Select 1 correct option.
a True
b False




Ans: b
Q4
What will be printed when the following program is compiled and run?
class Super
{
  public int getNumber( int a)
  {
    return 2;
  }
}
public class SubClass extends Super
{
  public int getNumber( int a, char ch)
  {
    return 4;
  }
  public static void main(String[] args)
  {
    System.out.println( new SubClass().getNumber(4) );
  }
}
Select 1 correct option.
a 4
b 2
c It will not compile.
d It will throw an exception at runtime.
e None of the above.
Ans:b
Q5
Consider the contents of following two files:
//File A.java
package a;
public class A
{
  A(){ }
  public void print(){ System.out.println("A"); }
}
//File B.java
package b;
import a.*;
public class B extends A
{
  B(){ }
  public void print(){ System.out.println("B"); }
  public static void main(String[] args)
  {
     new B();
  }
}
What will be printed when you try to compile and run class B?
 Select 1 correct option.
a It will print A.
b It will print B.
c It will not compile.
d It will compile but will not run.
e None of the above.


Ans:c
Q6
Consider the following code:
class Super
{
  static{ System.out.print("super "); }
}
class One
{
  static { System.out.print("one "); }
}
class Two extends Super
{
  static { System.out.print("two "); }
}
class Test
{
  public static void main(String[] args)
  {
    One o = null;
    Two t = new Two();
  }
}
What will be the output when class Test is run ?
Select 1 correct option.
a It will print one, super and two.
b It will print one, two and super.
c It will print super and two.
d It will print two and super
e None of the above.

Ans:c
Q7 What will the following code print when compiled and run?
class Base
{
           void methodA()
           {
                        System.out.println("base - MethodA");
           }
}
class Sub extends Base
{
           public void methodA()
           {
                        System.out.println("sub - MethodA");
           }
           public void methodB()
           {
                        System.out.println("sub - MethodB");
           }
           public static void main(String args[])
           {
                        Base b=new Sub(); //1
                        b.methodA(); //2
                        b.methodB(); //3
           }
}
Select 1 correct option.
a sub - MethodA , sub - MethodB
b base - MethodA , sub - MethodB
c Compile time error at //1
d Compile time error at //2
e Compile time error at //3                               Ans:   e
Q8
What will the following program print when run?

// Filename: TestClass.java
public class TestClass
{
   public static void main(String args[] ){ A b = new B("good bye"); }
}
class A
{
   A() { this("hello", " world"); }
   A(String s) { System.out.println(s); }
   A(String s1, String s2){ this(s1 + s2); }
}
class B extends A
{
   B(){ super("good bye"); };
   B(String s){ super(s, " world "); }
   B(String s1, String s2){ this(s1 + s2 + " ! "); }
}

Select 1 correct option.
a It will print "good bye".
b It will print "hello world".
c It will print "good bye world".
d It will print "good bye" followed by "hello world".
e It will print "hello world" followed by "good bye".           Ans: c
Q9
Which of the following access control keywords can be used to enable all the
subclasses to access a method defined in the base class?

Select 2 correct options
a public
b private
c protected
d No keyword is needed.




Ans:a,c
Q10
Consider the following class...

class MyString extends String
{
  MyString(){ super(); }
}

The above code will not compile.

Select 1 correct option.
a True
b False




Ans:a
Q11
Which of the following method definitions will prevent overriding of that method?

Select 4 correct options
a public final void method m1()
b public static void method m1()
c public static final void method m1()
d public abstract void method m1()
e private void method m1()




Ans:a,b,c,e
Q12
Given the following classes, what will be the output of compiling and running the class
Truck?
class Automobile
{
  public void drive() { System.out.println("Automobile: drive"); }
}
public class Truck extends Automobile
{
  public void drive() { System.out.println("Truck: drive"); }
  public static void main (String args [ ])
  {
    Automobile a = new Automobile();
    Truck t = new Truck();
    a.drive(); //1
    t.drive(); //2
    a = t; //3
    a.drive(); //4
  }
}
Select 1 correct option.
a Compiler error at line 3.
b Runtime error at line 3.
c It will print: Automobile: drive, Truck: drive, Automobile: drive, in that order.
d It will print: Automobile: drive, Truck: drive, Truck: drive, in that order.
e It will print: Automobile: drive, Automobile: drive, Automobile: drive, in that order.
Ans:d
Q13
What will be the result of attempting to compile and run the following program?

public class TestClass
{
  public static void main(String args[ ] )
  {
    A o1 = new C( );
    B o2 = (B) o1;
    System.out.println(o1.m1( ) );
    System.out.println(o2.i );
  }
}
class A { int i = 10; int m1( ) { return i; } }
class B extends A {at int i = 20; int m1() { return i; } }
class C extends B { int i = 30; int m1() { return i; } }

Select 1 correct option.
a The progarm will fail to compile.
b Class cast exception runtime.
c It will print 30, 20.
d It will print 30, 30.
e It will print 20, 20.                           Ans: c
Q14
Consider the following code:
class A
{
  A() { print(); }
  void print() { System.out.println("A"); }
}
class B extends A
{
  int i = Math.round(3.5f);
  public static void main(String[] args)
  {
    A a = new B();
    a.print();
  }
  void print() { System.out.println(i); }
}
What will be the output when class B is run ?
Select 1 correct option.
a It will print A, 4.
b It will print A, A
c It will print 0, 4
d It will print 4, 4
e None of the above.                          Ans: c
Q15
What will the following program print when run?
class Super
{
  public String toString()
  {
    return "4";
  }
}
public class SubClass extends Super
{
  public String toString()
  {
    return super.toString()+"3";
  }
  public static void main(String[] args)
  {
    System.out.println( new SubClass() );
  }
}
Select 1 correct option.
a 43
b 7
c It will not compile.
d It will throw an exception at runtime.
e None of the above.                              Ans: a

More Related Content

What's hot

Java practical(baca sem v)
Java practical(baca sem v)Java practical(baca sem v)
Java practical(baca sem v)
mehul patel
 
Navigating the xDD Alphabet Soup
Navigating the xDD Alphabet SoupNavigating the xDD Alphabet Soup
Navigating the xDD Alphabet Soup
Dror Helper
 
SoCal Code Camp 2015: An introduction to Java 8
SoCal Code Camp 2015: An introduction to Java 8SoCal Code Camp 2015: An introduction to Java 8
SoCal Code Camp 2015: An introduction to Java 8
Chaitanya Ganoo
 
Java Simple Programs
Java Simple ProgramsJava Simple Programs
Java Simple Programs
Upender Upr
 
Java Programming - 03 java control flow
Java Programming - 03 java control flowJava Programming - 03 java control flow
Java Programming - 03 java control flow
Danairat Thanabodithammachari
 
Inside PyMongo - MongoNYC
Inside PyMongo - MongoNYCInside PyMongo - MongoNYC
Inside PyMongo - MongoNYC
Mike Dirolf
 
12. Exception Handling
12. Exception Handling 12. Exception Handling
12. Exception Handling
Intro C# Book
 
Fnt software solutions placement paper
Fnt software solutions placement paperFnt software solutions placement paper
Fnt software solutions placement paperfntsofttech
 
Chap2 class,objects contd
Chap2 class,objects contdChap2 class,objects contd
Chap2 class,objects contd
raksharao
 
Java programs
Java programsJava programs
Simple Java Programs
Simple Java ProgramsSimple Java Programs
Simple Java ProgramsAravindSankaran
 
E5
E5E5
E5
lksoo
 
UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 2
UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 2UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 2
UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 2
Knowledge Center Computer
 
Part - 2 Cpp programming Solved MCQ
Part - 2  Cpp programming Solved MCQ Part - 2  Cpp programming Solved MCQ
Part - 2 Cpp programming Solved MCQ
Knowledge Center Computer
 
Loop
LoopLoop
conditional statements
conditional statementsconditional statements
conditional statements
James Brotsos
 
Simulado java se 7 programmer
Simulado java se 7 programmerSimulado java se 7 programmer
Simulado java se 7 programmer
Miguel Vilaca
 
Java PRACTICAL file
Java PRACTICAL fileJava PRACTICAL file
Java PRACTICAL file
RACHIT_GUPTA
 
Inheritance and-polymorphism
Inheritance and-polymorphismInheritance and-polymorphism
Inheritance and-polymorphism
Usama Malik
 
20.4 Java interfaces and abstraction
20.4 Java interfaces and abstraction20.4 Java interfaces and abstraction
20.4 Java interfaces and abstraction
Intro C# Book
 

What's hot (20)

Java practical(baca sem v)
Java practical(baca sem v)Java practical(baca sem v)
Java practical(baca sem v)
 
Navigating the xDD Alphabet Soup
Navigating the xDD Alphabet SoupNavigating the xDD Alphabet Soup
Navigating the xDD Alphabet Soup
 
SoCal Code Camp 2015: An introduction to Java 8
SoCal Code Camp 2015: An introduction to Java 8SoCal Code Camp 2015: An introduction to Java 8
SoCal Code Camp 2015: An introduction to Java 8
 
Java Simple Programs
Java Simple ProgramsJava Simple Programs
Java Simple Programs
 
Java Programming - 03 java control flow
Java Programming - 03 java control flowJava Programming - 03 java control flow
Java Programming - 03 java control flow
 
Inside PyMongo - MongoNYC
Inside PyMongo - MongoNYCInside PyMongo - MongoNYC
Inside PyMongo - MongoNYC
 
12. Exception Handling
12. Exception Handling 12. Exception Handling
12. Exception Handling
 
Fnt software solutions placement paper
Fnt software solutions placement paperFnt software solutions placement paper
Fnt software solutions placement paper
 
Chap2 class,objects contd
Chap2 class,objects contdChap2 class,objects contd
Chap2 class,objects contd
 
Java programs
Java programsJava programs
Java programs
 
Simple Java Programs
Simple Java ProgramsSimple Java Programs
Simple Java Programs
 
E5
E5E5
E5
 
UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 2
UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 2UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 2
UGC-NET, GATE and all IT Companies Interview C++ Solved Questions PART - 2
 
Part - 2 Cpp programming Solved MCQ
Part - 2  Cpp programming Solved MCQ Part - 2  Cpp programming Solved MCQ
Part - 2 Cpp programming Solved MCQ
 
Loop
LoopLoop
Loop
 
conditional statements
conditional statementsconditional statements
conditional statements
 
Simulado java se 7 programmer
Simulado java se 7 programmerSimulado java se 7 programmer
Simulado java se 7 programmer
 
Java PRACTICAL file
Java PRACTICAL fileJava PRACTICAL file
Java PRACTICAL file
 
Inheritance and-polymorphism
Inheritance and-polymorphismInheritance and-polymorphism
Inheritance and-polymorphism
 
20.4 Java interfaces and abstraction
20.4 Java interfaces and abstraction20.4 Java interfaces and abstraction
20.4 Java interfaces and abstraction
 

Viewers also liked

Chap3 inheritance
Chap3 inheritanceChap3 inheritance
Chap3 inheritance
raksharao
 
Inheritance
InheritanceInheritance
Inheritance
Daman Toor
 
itft-Inheritance in java
itft-Inheritance in javaitft-Inheritance in java
itft-Inheritance in java
Atul Sehdev
 
Java inheritance
Java inheritanceJava inheritance
Java inheritance
Arati Gadgil
 
Inheritance in JAVA PPT
Inheritance  in JAVA PPTInheritance  in JAVA PPT
Inheritance in JAVA PPT
Pooja Jaiswal
 

Viewers also liked (6)

Chap3 inheritance
Chap3 inheritanceChap3 inheritance
Chap3 inheritance
 
Inheritance
InheritanceInheritance
Inheritance
 
itft-Inheritance in java
itft-Inheritance in javaitft-Inheritance in java
itft-Inheritance in java
 
Java inheritance
Java inheritanceJava inheritance
Java inheritance
 
Inheritance in JAVA PPT
Inheritance  in JAVA PPTInheritance  in JAVA PPT
Inheritance in JAVA PPT
 
Inheritance
InheritanceInheritance
Inheritance
 

Similar to Java Inheritance

2 object orientation-copy
2 object orientation-copy2 object orientation-copy
2 object orientation-copyJoel Campos
 
Core java
Core javaCore java
Core java
prabhatjon
 
Indus Valley Partner aptitude questions and answers
Indus Valley Partner aptitude questions and answersIndus Valley Partner aptitude questions and answers
Indus Valley Partner aptitude questions and answers
Sushant Choudhary
 
Java concurrency questions and answers
Java concurrency questions and answers Java concurrency questions and answers
Java concurrency questions and answers
CodeOps Technologies LLP
 
Uta005
Uta005Uta005
Uta005
Daman Toor
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Mar-2021_L14...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Mar-2021_L14...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Mar-2021_L14...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Mar-2021_L14...
MaruMengesha
 
Review Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfReview Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdf
mayorothenguyenhob69
 
sample_midterm.pdf
sample_midterm.pdfsample_midterm.pdf
sample_midterm.pdf
EFRENlazarte2
 
Multiple choice questions for Java io,files and inheritance
Multiple choice questions for Java io,files and inheritanceMultiple choice questions for Java io,files and inheritance
Multiple choice questions for Java io,files and inheritance
Abishek Purushothaman
 
Second chapter-java
Second chapter-javaSecond chapter-java
Second chapter-java
Ahmad sohail Kakar
 
OCJP Samples Questions: Exceptions and assertions
OCJP Samples Questions: Exceptions and assertionsOCJP Samples Questions: Exceptions and assertions
OCJP Samples Questions: Exceptions and assertions
Hari kiran G
 
C#
C#C#
Comp 328 final guide
Comp 328 final guideComp 328 final guide
Comp 328 final guide
krtioplal
 
Unit-3 Practice Programs-5.docx
Unit-3 Practice Programs-5.docxUnit-3 Practice Programs-5.docx
Unit-3 Practice Programs-5.docx
R.K.College of engg & Tech
 
Technical aptitude test 2 CSE
Technical aptitude test 2 CSETechnical aptitude test 2 CSE
Technical aptitude test 2 CSE
Sujata Regoti
 
Language fundamentals ocjp
Language fundamentals ocjpLanguage fundamentals ocjp
Language fundamentals ocjp
Bhavishya sharma
 
Java and j2ee_lab-manual
Java and j2ee_lab-manualJava and j2ee_lab-manual
Java and j2ee_lab-manual
hanumanthu mothukuru
 
200 mcq c++(Ankit dubey)
200 mcq c++(Ankit dubey)200 mcq c++(Ankit dubey)
200 mcq c++(Ankit dubey)
Ankit Dubey
 

Similar to Java Inheritance (20)

2 object orientation-copy
2 object orientation-copy2 object orientation-copy
2 object orientation-copy
 
Core java
Core javaCore java
Core java
 
Indus Valley Partner aptitude questions and answers
Indus Valley Partner aptitude questions and answersIndus Valley Partner aptitude questions and answers
Indus Valley Partner aptitude questions and answers
 
Java concurrency questions and answers
Java concurrency questions and answers Java concurrency questions and answers
Java concurrency questions and answers
 
Uta005
Uta005Uta005
Uta005
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Mar-2021_L14...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Mar-2021_L14...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Mar-2021_L14...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_04-Mar-2021_L14...
 
Review Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdfReview Questions for Exam 10182016 1. public class .pdf
Review Questions for Exam 10182016 1. public class .pdf
 
sample_midterm.pdf
sample_midterm.pdfsample_midterm.pdf
sample_midterm.pdf
 
Multiple choice questions for Java io,files and inheritance
Multiple choice questions for Java io,files and inheritanceMultiple choice questions for Java io,files and inheritance
Multiple choice questions for Java io,files and inheritance
 
Second chapter-java
Second chapter-javaSecond chapter-java
Second chapter-java
 
Scjp6.0
Scjp6.0Scjp6.0
Scjp6.0
 
OCJP Samples Questions: Exceptions and assertions
OCJP Samples Questions: Exceptions and assertionsOCJP Samples Questions: Exceptions and assertions
OCJP Samples Questions: Exceptions and assertions
 
C#
C#C#
C#
 
Comp 328 final guide
Comp 328 final guideComp 328 final guide
Comp 328 final guide
 
Unit-3 Practice Programs-5.docx
Unit-3 Practice Programs-5.docxUnit-3 Practice Programs-5.docx
Unit-3 Practice Programs-5.docx
 
Technical aptitude test 2 CSE
Technical aptitude test 2 CSETechnical aptitude test 2 CSE
Technical aptitude test 2 CSE
 
Language fundamentals ocjp
Language fundamentals ocjpLanguage fundamentals ocjp
Language fundamentals ocjp
 
Java and j2ee_lab-manual
Java and j2ee_lab-manualJava and j2ee_lab-manual
Java and j2ee_lab-manual
 
Class 6 2ciclo
Class 6 2cicloClass 6 2ciclo
Class 6 2ciclo
 
200 mcq c++(Ankit dubey)
200 mcq c++(Ankit dubey)200 mcq c++(Ankit dubey)
200 mcq c++(Ankit dubey)
 

Recently uploaded

FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
DianaGray10
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
Fwdays
 

Recently uploaded (20)

FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 

Java Inheritance

  • 2. Q1 .Consider the following code: class Base { private float f = 1.0f; protected void setF(float f1){ this.f = f1; } } class Base2 extends Base { private float f = 2.0f; //1 } Which of the following options is a valid example of overriding? Select 2 correct options a protected void setF(float f1){ this.f = 2*f1; } b public void setF(double f1){ this.f = (float) 2*f1; } c public void setF(float f1){ this.f = 2*f1; } d private void setF(float f1){ this.f = 2*f1; } e float setF(float f1){ this.f = 2*f1; return f;} Ans: a,c
  • 3. Q2 You are modeling a class hierarchy for living things. You have a class LivingThing which has an abstract method reproduce(). Now, you want to have 2 subclasses of LivingThing, Plant and Animal. Obviously, both do reproduce but the mechanisms are different. What would you do? Select 1 correct option. a Overload the reproduce method in Plant and Animal Clases b Overload the reproduce method in LivingThing Class. c Override the reproduce method in Plant and Animal Clases d Either overload or override, it depends on the taste of the designer. Ans: c
  • 4. Q3 An abstract method cannot be overridden. Select 1 correct option. a True b False Ans: b
  • 5. Q4 What will be printed when the following program is compiled and run? class Super { public int getNumber( int a) { return 2; } } public class SubClass extends Super { public int getNumber( int a, char ch) { return 4; } public static void main(String[] args) { System.out.println( new SubClass().getNumber(4) ); } } Select 1 correct option. a 4 b 2 c It will not compile. d It will throw an exception at runtime. e None of the above. Ans:b
  • 6. Q5 Consider the contents of following two files: //File A.java package a; public class A { A(){ } public void print(){ System.out.println("A"); } } //File B.java package b; import a.*; public class B extends A { B(){ } public void print(){ System.out.println("B"); } public static void main(String[] args) { new B(); } } What will be printed when you try to compile and run class B? Select 1 correct option. a It will print A. b It will print B. c It will not compile. d It will compile but will not run. e None of the above. Ans:c
  • 7. Q6 Consider the following code: class Super { static{ System.out.print("super "); } } class One { static { System.out.print("one "); } } class Two extends Super { static { System.out.print("two "); } } class Test { public static void main(String[] args) { One o = null; Two t = new Two(); } } What will be the output when class Test is run ? Select 1 correct option. a It will print one, super and two. b It will print one, two and super. c It will print super and two. d It will print two and super e None of the above. Ans:c
  • 8. Q7 What will the following code print when compiled and run? class Base { void methodA() { System.out.println("base - MethodA"); } } class Sub extends Base { public void methodA() { System.out.println("sub - MethodA"); } public void methodB() { System.out.println("sub - MethodB"); } public static void main(String args[]) { Base b=new Sub(); //1 b.methodA(); //2 b.methodB(); //3 } } Select 1 correct option. a sub - MethodA , sub - MethodB b base - MethodA , sub - MethodB c Compile time error at //1 d Compile time error at //2 e Compile time error at //3 Ans: e
  • 9. Q8 What will the following program print when run? // Filename: TestClass.java public class TestClass { public static void main(String args[] ){ A b = new B("good bye"); } } class A { A() { this("hello", " world"); } A(String s) { System.out.println(s); } A(String s1, String s2){ this(s1 + s2); } } class B extends A { B(){ super("good bye"); }; B(String s){ super(s, " world "); } B(String s1, String s2){ this(s1 + s2 + " ! "); } } Select 1 correct option. a It will print "good bye". b It will print "hello world". c It will print "good bye world". d It will print "good bye" followed by "hello world". e It will print "hello world" followed by "good bye". Ans: c
  • 10. Q9 Which of the following access control keywords can be used to enable all the subclasses to access a method defined in the base class? Select 2 correct options a public b private c protected d No keyword is needed. Ans:a,c
  • 11. Q10 Consider the following class... class MyString extends String { MyString(){ super(); } } The above code will not compile. Select 1 correct option. a True b False Ans:a
  • 12. Q11 Which of the following method definitions will prevent overriding of that method? Select 4 correct options a public final void method m1() b public static void method m1() c public static final void method m1() d public abstract void method m1() e private void method m1() Ans:a,b,c,e
  • 13. Q12 Given the following classes, what will be the output of compiling and running the class Truck? class Automobile { public void drive() { System.out.println("Automobile: drive"); } } public class Truck extends Automobile { public void drive() { System.out.println("Truck: drive"); } public static void main (String args [ ]) { Automobile a = new Automobile(); Truck t = new Truck(); a.drive(); //1 t.drive(); //2 a = t; //3 a.drive(); //4 } } Select 1 correct option. a Compiler error at line 3. b Runtime error at line 3. c It will print: Automobile: drive, Truck: drive, Automobile: drive, in that order. d It will print: Automobile: drive, Truck: drive, Truck: drive, in that order. e It will print: Automobile: drive, Automobile: drive, Automobile: drive, in that order. Ans:d
  • 14. Q13 What will be the result of attempting to compile and run the following program? public class TestClass { public static void main(String args[ ] ) { A o1 = new C( ); B o2 = (B) o1; System.out.println(o1.m1( ) ); System.out.println(o2.i ); } } class A { int i = 10; int m1( ) { return i; } } class B extends A {at int i = 20; int m1() { return i; } } class C extends B { int i = 30; int m1() { return i; } } Select 1 correct option. a The progarm will fail to compile. b Class cast exception runtime. c It will print 30, 20. d It will print 30, 30. e It will print 20, 20. Ans: c
  • 15. Q14 Consider the following code: class A { A() { print(); } void print() { System.out.println("A"); } } class B extends A { int i = Math.round(3.5f); public static void main(String[] args) { A a = new B(); a.print(); } void print() { System.out.println(i); } } What will be the output when class B is run ? Select 1 correct option. a It will print A, 4. b It will print A, A c It will print 0, 4 d It will print 4, 4 e None of the above. Ans: c
  • 16. Q15 What will the following program print when run? class Super { public String toString() { return "4"; } } public class SubClass extends Super { public String toString() { return super.toString()+"3"; } public static void main(String[] args) { System.out.println( new SubClass() ); } } Select 1 correct option. a 43 b 7 c It will not compile. d It will throw an exception at runtime. e None of the above. Ans: a