Niveditha Daneesh 1517106058 Information Technology Wipro Talent Next 2021 OOPS - Assignment

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 9

Niveditha Daneesh

1517106058
Information Technology
Wipro Talent Next 2021
OOPS – Assignment
1 import java.util.*;
class A{
String na;
String em;
char ge;

A(String na, String em, char ge){


this.na = na;
this.em = em;
this.ge = ge;} }
class B{
String na;
Author au;
double pr;
int q;
B(String na, Author au, double pr ,int q){
this.na = na;
this.au = au;
this.pr = pr;
this.q = q;}
void setName(String name){
this.name = name;}
void setAuthor(Author author){
this.author = author;}
void setPrice(double price){
this.price = price;}
void setQtyInStock(int qtyInStock){
this.qtyInStock = qtyInStock;}
String getName()
{
return name;
}
Author getAuthor()
{
return author;
}
double getPrice()
{
return price;
}
int getQtyInStock()
{
return qtyInStock;
}
} public class main
{
public static void main(String[] args)
{
A author = new A("Javed","[email protected]",'M');
B book = new B("WiproS",author,500.99,3);

book.setName("JavaWorld");
System.out.println(book.getName());
String[] authDetails = book.getAuthor().toString();
for(String strr: authDetails)
{
System.out.println(strr);
}
}
}
2 import java.util.*;
public class A {
public A() {
System.out.println("A new animal has been created!");
}
public void s() {
System.out.println("An animal sleeps...");
}
public void e() {
System.out.println("An animal eats...");
}
}
public class B extends A {
public B() {
super();
System.out.println("A new bird has been created!");
}
public void s() {
System.out.println("A bird sleeps...");
}
public void e() {
System.out.println("A bird eats...");
}
}
public class D extends A {
public D() {
super();
System.out.println("A new dog has been created!");
}
public void s() {
System.out.println("A dog sleeps...");
}
public void e() {
System.out.println("A dog eats...");
}
}

public class MainClass {


public static void main(String[] args) {
A animal = new A();
B bird = new B();
D dog = new D();
System.out.println();
}
}
3 import java.util.*;
class P
{
String n;
P(String s)
{
n=s;
}
void getName()
{
System.out.println("Name is "+n);
}
void setName(String sa)
{
n=sa;
}
}
class sub extends P
{
int Prn;
String course;
subPerson(String s,int P,String co)
{
n=s;
Prn=P;
course=co;
}
void displayal()
{
System.out.println("Name is ");
System.out.println("PRN is "+Prn);
System.out.println("course is "+course);
}
}
class main
{
public static void main(String args[])
{
int area,volumea;
sub h1 = new sub("Abhishek",20,"MBA");
h1.displayal();
}
}
4 import java.util.*;
class f
{
protected char name, taste, size ;
scanner sc = new scanner ( system. in );
public void eat ( ){
scanner sc = new scanner ( system. in );
system. out. println ( "enter the name of the fruit " ) ;
name = nextChar ( ) ;
system. out. println ( " please provide the taste of the fruit " ) ;
taste = nextChar ( ) ;
system. out. println ( " Name of the fruit is: " + name ) ;
system. out. println ( " Taste of the fruit is: " + taste ) ;
}
}
class a extends f
{
void eat ( )
{
system. out. println ( " Name of the fruit is Apple " ) ;
system. out. println ( " Taste of the fruit is sweet " ) ;
}
}
class o extends f
{
public void eat ( )
{
system. out. println ( " Name of the fruit is Orange " ) ;
system. out. println ( " Taste of the fruit is sour " ) ;
}
}
class main
{
public static void main ( string args )
{
a A = new a ( ) ;
A . eat ( ) ;
o O = new o ( ) ;
O . eat ( ) ;
}
}
5 import java.util.*;
class sh
{
void draw()
{
System.out.println("Drawing Shape");
}
void erase()
{
System.out.println("erasing shape");
}
}
class ci extends sh
{
void draw()
{
System.out.println("drawing circle");
}
void erase()
{
System.out.println("erasing circle");
}
}
class tri extends sh
{
void draw()
{
System.out.println("drawing triangle");
}
void erase()
{
System.out.println("erasing triangle");
}
}
class sq extends sh
{
void draw()
{
System.out.println("drawing square");
}
void erase()
{
System.out.println("erasing square");
}
}
public class main
{
public static void main(String args[])
{
sh c=new ci();
sh t=new tri();
sh s=new sq();
c.draw();
c.erase();
t.draw();
t.triangle();
s.draw();
s.erase();
}
}

You might also like