Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
7 views
Java assignment-1
Java important questions for semester exams for 3rd semester
Uploaded by
Johnny GAMER
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save Java assignment-1 For Later
Download
Save
Save Java assignment-1 For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
7 views
Java assignment-1
Java important questions for semester exams for 3rd semester
Uploaded by
Johnny GAMER
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save Java assignment-1 For Later
Carousel Previous
Carousel Next
Save
Save Java assignment-1 For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 17
Search
Fullscreen
r Thursday ABI-aH ASSIGNMENT - 03 =— == => v Define inheritance and éxplato the digevert te 4 iphentanee yaith relevant examples « 7% aa into Acquiring the propertiee from one class (parent class) Gub class (child etass) ts caned Sohenitan ce” ~ Parent class 18 also called super class ov base class and child class ts called as a Sub-class OF deived class - ‘Type 4 Tnheritanee ! \ Single - level “fin evitanee | sub class Wheo a class inherits propatis from another class then iF is called at Single « level ~inhentanes « $x! class Animal L void eat C) t Syetern out : painelo (“eating”) ; 42class Dog extends Anima) t void bavk() c Sysern out priotto ("barking"); | s J Class Test Tohentanee t public static void main ( String CIarqs) t Dog dz new Dog 0) 5, d+ baat 095 deat; y y. Output * barking eating. AY Mult level ~ Sheritance ? Class -C| | : | Wathen there {8 a chain of inh ertance , then it '¢ Known ag multi-level Tnhevtanee -Example! Class Animal t vod att) t System: out * print lo (“eating”); 3 Claes hog extends Animal t void barke) t System: cut: printto ("barking"); 4] 3 class Baby Dog extends Dog t vord sleep c s System sout print (ucteep”); x + Class Test Inhenitanee public static wid mai (String args C1) < Baby Dog bs new Baby Pog Oe b: sleepO)s b- bavk0); 5 y b- eat); 44 aput ut! Sleeping a barking eating, 37 Heivarehical = Level-Tnhevitanee: 9 two oF more classes Inherit King\e class then {4 ts Knoven whet as Herarchical -Level~ Mheitance - sxample class Animal eC void wat Cc) ic System + out + printlo (“eating”); 3 class Dog extends Anima) t void bark ¢) € Systern out “print lo (“'baaktng")5 y s ; class cat extends Anienal
out: prtatta (95: 4S); System out: pratty (°K! 94K); fot Colthy 4 System out printia ‘ita 3 class main class < public stare void mai (Sting Ca8qs) Bb » new @ (1421395 br add HO 50 NN eeebraddikey; * 3 af gurput' (it}>)3 th Ki3 (ab t4 y. 8) Super 1 used {p invoke ‘gupe? clase hittodl! ~hheo parent class method and child dass method names are damt {0 otherusords the method ts overiden - - class Animal 4 votd eat ©) t System - out: griatlo (rath animals can eat"); yord cat) L | | | 3 class Dog extends Animal System -out “pantlo (eating bread”) 5 iy void bak) 4 System: out priate (“basking ") 5 3 51 ee ae ee a ee ee| : 1 Void usorke ) 4 Super -catC) 5 Super barker; 3 Class main class t public State void mato (Sting args C3) ¢ Dog d+ new Dogt); d-soak 0); 4 Sutput AM animals can eat PP hwite a program yohich {mplemanés the usage oy JAVA method overiamg Tt te used 0 provide Specific implementation ya method that je alrady provided by its Super etoss » R te basteatty used for oun, time polyriophiem « class Bank v int getRate of Aoeerest 0) ¢ xetumn 0; a 82 —_—eeeeclass SOL extends Bank & fat get Rateop Tnterest (9 £ etn 8) ¥ s crass 1CtCl extends Bank ¢ int getRateof Loterest 69 ¢ vetunn F 5 s J Class AXIS extends Bank ¢ int get Rateog Taterest 9 £ retum 4) y 5 tlass Test 9 ¢ public statie void main (String CJ.axg8) ¢ SBI Se new SBI 0); Jere) | = nevo icteley, Axis az neva AXIS CO); Syston out: pret ("S01 Rate of Tateest °F S* get Rate of Jaterest) j Systeen- out’ prinetn (eter Rate af Interests” ¢ (gp tle eat oO); ; 53 ie ee ee eee eeni Systera out: print (“Axis Rate af Anterest 2" 4 age hate of ' LatorestO) 5 eY, Output! SB Rate of Tntorest ! 8 lerel Rate of tnterest | Anis kate &p gaterest Ty, 4 Define abshact classes and Lxplain the use oF abstract method, and classes sith velevant examples » ~ Abshact Classes! We aan digine a superclass that declares the ere of a given abshacton, usithout providing a Complete implementation af every method. ‘fhe gunaral form of a9 abstract dass typename Cpavameter - ist ) 5 ~ using abstact methods and classes! abstract class Figure € double dim 4! double dim 9 + Figure (double a, double b) t dim dea, dim 92, is, abshact double area C)5 f 6class Rectangle ortends Figure t Rectangle (double a, double b) ¢ Super (a,b) ‘ y double areal) System -out * printto (“Sherde Area for fastangle.”) 5 rebum diel din 25 ¥ 4 class Triangle extends Figure t Frangle (double a , double b) eC Supyr (arb oh x double areal) 3 aH Systern - out printlo ("Dneide Area for Triangu - )5 rear dim) aim] & ; ¥ A class Abstract Anat public static void mato (String CJargs) € /| Figure = new figure (10) 5 fettong tu o> co Rectang le (9:8); friangle £= new ‘Triangle (10,8 J; Figure fignet 5 a Pe OS eeAgr -r; ; System - out’ printlo ("Area te "4 gignep a7e0)3 figref et) : Syste out: prinélo (“Area is” a feguep ard); ¥ x Butput’ theide area for reciangle area is 45-60 Inside area for Trhangls aua '¢ 40°04. BY Depi tfine Tntegace by undustanding the relationship. betuown classes and jotexawe usith guitable example os ' Teteyace! In Java, an interjace fe a blue print of a class « FR has static conctants and abshact methods - ~ The liteaee in Java te a mechaniem to acheive abstraction. ~ Undastand yetatonship between classes and Interfaces! An jntexface ie defined much like a class -General foun of an interface ! access intaqace name t type final _— varname 4 = value) type Avaal _ varname 9 = value} 44ype Pinal — yasname N= value } ret “Aype method -name 4 (pavametor ~ list ) 5 Yeturn - type method- name 9 (parameter - 184 ) 5 , - Interface Sayable & Statice void say Louder (String meq) 4 System put pratlo (msg) 4 ¥ 3 public class Default Methods implemends Sayable € public static void main (Shing CJarqs) ¢ Sayable saylouder (“Hetloooo- Boe 5) x J. Output « Helloooo..-.. 57a” tiple foheritane, fn i 6 nite program ughich implements maul Tava by inteyaee - ode} Interface Sayable 4 default void say C) Say Something 0) 5 ¥ : Pavate void Saysomething () 4 ‘ F Syston out® priatlo (*Hello--- Sm private method”): Ss ee class private Tukuface Spleen ts Sayable i public stave vord main [ Sting CI 429s) L Sayable = neva Private Tkerface 095 S sayl); 5 4 Outpur! Hello... T'm private method n, 58
You might also like
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
From Everand
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
Mark Manson
4/5 (6129)
Principles: Life and Work
From Everand
Principles: Life and Work
Ray Dalio
4/5 (627)
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
From Everand
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
Brene Brown
4/5 (1148)
Never Split the Difference: Negotiating As If Your Life Depended On It
From Everand
Never Split the Difference: Negotiating As If Your Life Depended On It
Chris Voss
4.5/5 (935)
The Glass Castle: A Memoir
From Everand
The Glass Castle: A Memoir
Jeannette Walls
4/5 (8215)
Grit: The Power of Passion and Perseverance
From Everand
Grit: The Power of Passion and Perseverance
Angela Duckworth
4/5 (631)
Sing, Unburied, Sing: A Novel
From Everand
Sing, Unburied, Sing: A Novel
Jesmyn Ward
4/5 (1253)
The Perks of Being a Wallflower
From Everand
The Perks of Being a Wallflower
Stephen Chbosky
4/5 (8365)
Shoe Dog: A Memoir by the Creator of Nike
From Everand
Shoe Dog: A Memoir by the Creator of Nike
Phil Knight
4.5/5 (860)
Her Body and Other Parties: Stories
From Everand
Her Body and Other Parties: Stories
Carmen Maria Machado
4/5 (877)
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
From Everand
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
Ben Horowitz
4.5/5 (361)
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
From Everand
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
Margot Lee Shetterly
4/5 (954)
Steve Jobs
From Everand
Steve Jobs
Walter Isaacson
4/5 (2923)
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
From Everand
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
Ashlee Vance
4.5/5 (484)
The Emperor of All Maladies: A Biography of Cancer
From Everand
The Emperor of All Maladies: A Biography of Cancer
Siddhartha Mukherjee
4.5/5 (277)
A Man Called Ove: A Novel
From Everand
A Man Called Ove: A Novel
Fredrik Backman
4.5/5 (4972)
Angela's Ashes: A Memoir
From Everand
Angela's Ashes: A Memoir
Frank McCourt
4.5/5 (444)
Brooklyn: A Novel
From Everand
Brooklyn: A Novel
Colm Toibin
3.5/5 (2061)
The Art of Racing in the Rain: A Novel
From Everand
The Art of Racing in the Rain: A Novel
Garth Stein
4/5 (4281)
The Yellow House: A Memoir (2019 National Book Award Winner)
From Everand
The Yellow House: A Memoir (2019 National Book Award Winner)
Sarah M. Broom
4/5 (100)
The Little Book of Hygge: Danish Secrets to Happy Living
From Everand
The Little Book of Hygge: Danish Secrets to Happy Living
Meik Wiking
3.5/5 (447)
Yes Please
From Everand
Yes Please
Amy Poehler
4/5 (1987)
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
From Everand
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
Gilbert King
4.5/5 (278)
The World Is Flat 3.0: A Brief History of the Twenty-first Century
From Everand
The World Is Flat 3.0: A Brief History of the Twenty-first Century
Thomas L. Friedman
3.5/5 (2283)
Bad Feminist: Essays
From Everand
Bad Feminist: Essays
Roxane Gay
4/5 (1068)
The Woman in Cabin 10
From Everand
The Woman in Cabin 10
Ruth Ware
3.5/5 (2641)
The Outsider: A Novel
From Everand
The Outsider: A Novel
Stephen King
4/5 (1993)
A Tree Grows in Brooklyn
From Everand
A Tree Grows in Brooklyn
Betty Smith
4.5/5 (1936)
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
From Everand
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
Viet Thanh Nguyen
4.5/5 (125)
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
From Everand
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
Dave Eggers
3.5/5 (692)
Team of Rivals: The Political Genius of Abraham Lincoln
From Everand
Team of Rivals: The Political Genius of Abraham Lincoln
Doris Kearns Goodwin
4.5/5 (1912)
Wolf Hall: A Novel
From Everand
Wolf Hall: A Novel
Hilary Mantel
4/5 (4074)
On Fire: The (Burning) Case for a Green New Deal
From Everand
On Fire: The (Burning) Case for a Green New Deal
Naomi Klein
4/5 (75)
Fear: Trump in the White House
From Everand
Fear: Trump in the White House
Bob Woodward
3.5/5 (830)
Manhattan Beach: A Novel
From Everand
Manhattan Beach: A Novel
Jennifer Egan
3.5/5 (901)
Rise of ISIS: A Threat We Can't Ignore
From Everand
Rise of ISIS: A Threat We Can't Ignore
Jay Sekulow
3.5/5 (143)
John Adams
From Everand
John Adams
David McCullough
4.5/5 (2544)
The Light Between Oceans: A Novel
From Everand
The Light Between Oceans: A Novel
M L Stedman
4.5/5 (790)
OS-assignment-1
PDF
No ratings yet
OS-assignment-1
1 page
CAED Lab Prac.
PDF
No ratings yet
CAED Lab Prac.
1 page
Program11
PDF
No ratings yet
Program11
9 pages
SCR
PDF
No ratings yet
SCR
27 pages
Moment of Inertia
PDF
No ratings yet
Moment of Inertia
11 pages
Python Basics
PDF
No ratings yet
Python Basics
23 pages
Indian Constitution 2
PDF
No ratings yet
Indian Constitution 2
8 pages
SFH Previous Year Question Paper
PDF
100% (2)
SFH Previous Year Question Paper
9 pages
Module-1 Sensors
PDF
No ratings yet
Module-1 Sensors
31 pages
The Unwinding: An Inner History of the New America
From Everand
The Unwinding: An Inner History of the New America
George Packer
4/5 (45)
Little Women
From Everand
Little Women
Louisa May Alcott
4/5 (105)
The Constant Gardener: A Novel
From Everand
The Constant Gardener: A Novel
John le Carré
3.5/5 (109)