0% found this document useful (0 votes)
9 views4 pages

DAY4 Java

Yes

Uploaded by

donreturnwell
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views4 pages

DAY4 Java

Yes

Uploaded by

donreturnwell
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

DEPARTMENTOF

COMPUTERSCIENCE&ENGINEERING

DAY- 4
Student Name: Himanshu UID: 21BCS5642
Branch: CSE Section/Group: 904-B
Subject Name: JAVA Date: 31/05/24

Ques 1) Reverse Integer


class Solution {
public int reverse(int x) {
long reverse = 0;
int temp;

while (x != 0) {
temp = x % 10;
reverse = reverse * 10 + temp;
x = x / 10;

if (reverse > Integer.MAX_VALUE || reverse < Integer.MIN_VALUE)


{
return 0;
}
}

return (int)reverse;
}
}
DEPARTMENTOF
COMPUTERSCIENCE&ENGINEERING

Ques 2) Java Method Overriding 2 (Super Keyword)


import java.util.*;
import java.io.*;

class BiCycle{
String define_me(){
return "a vehicle with pedals.";
}
}

class MotorCycle extends BiCycle{


String define_me(){
return "a cycle with an engine.";
}

MotorCycle(){
System.out.println("Hello I am a motorcycle, I am "+ define_me());

String temp=super.define_me();
System.out.println("My ancestor is a cycle who is "+ temp );
}

}
class Solution{
public static void main(String []args){
MotorCycle M=new MotorCycle();
}
}
DEPARTMENTOF
COMPUTERSCIENCE&ENGINEERING

Ques 3) Java Method Overriding


import java.util.*;
class Sports{
String getName(){
return "Generic Sports";
}
void getNumberOfTeamMembers(){
System.out.println( "Each team has n players in " + getName() );
}
}
class Soccer extends Sports{
@Override
String getName(){
return "Soccer Class";
}
@Override
void getNumberOfTeamMembers() {
System.out.println("Each team has 11 players in " + getName());
}
}
public class Solution{

public static void main(String []args){


Sports c1 = new Sports();
Soccer c2 = new Soccer();
System.out.println(c1.getName());
c1.getNumberOfTeamMembers();
System.out.println(c2.getName());
c2.getNumberOfTeamMembers();
}
}
DEPARTMENTOF
COMPUTERSCIENCE&ENGINEERING

Ques 4) Java Abstract Class


import java.util.*;
abstract class Book{
String title;
abstract void setTitle(String s);
String getTitle(){
return title;
}

}
class MyBook extends Book {
void setTitle(String s){
this.title = s;
}
}
public class Main{

public static void main(String []args){


Scanner sc=new Scanner(System.in);
String title=sc.nextLine();
MyBook new_novel=new MyBook();
new_novel.setTitle(title);
System.out.println("The title is: "+new_novel.getTitle());
sc.close();

}
}

You might also like