0% found this document useful (0 votes)
6 views5 pages

Java Object-Oriented Programming Examples

The document contains multiple Java classes demonstrating basic object-oriented programming concepts. It includes a SimpleObject class with a constructor, a Number class for number properties and checks, a Room class for room details, and a Shape class with subclasses for different shapes. Each class has a main method for execution and interaction with user input.

Uploaded by

boytechnical717
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)
6 views5 pages

Java Object-Oriented Programming Examples

The document contains multiple Java classes demonstrating basic object-oriented programming concepts. It includes a SimpleObject class with a constructor, a Number class for number properties and checks, a Room class for room details, and a Shape class with subclasses for different shapes. Each class has a main method for execution and interaction with user input.

Uploaded by

boytechnical717
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

package lecturesOfJava;

public class SimpleObject {


public SimpleObject() {
[Link]("this is constructor");
}

public static void main(String[] args) {


SimpleObject obj=new SimpleObject();
}

package lecturesOfJava;
import [Link];
public class Number {
int number;
public Number(int number) {
[Link]=number;
}
public boolean isZero(int number) {
return number==0;
}
public boolean isPositive(int number) {
return number>0;
}
public boolean isNegative(int number) {
return number<0;
}
public boolean isOdd(int number) {
return number%2!=0;
}
public boolean isEven(int number) {
return number%2==0;
}
public boolean isPrime(int number) {
int n=number/2;
for(int i=2;i<n;i++) {
if(number%i==0) {
return false;
}
}
return true;
}
public boolean isArmstrong(int number) {
int n=number;
int remainder=(int)Math.log10(n);
int result=0;
while (n != 0)
{
remainder = n % 10;
result += [Link](remainder, 3);
n /= 10;
}
if(number ==result) {
return true;
}else {
return false;
}

}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner([Link]);
Number obj=new Number([Link]());
[Link]([Link]([Link]));
[Link]([Link]([Link]));
[Link]([Link]([Link]));
[Link]([Link]([Link]));
[Link]([Link]([Link]));
[Link]([Link]([Link]));
[Link]([Link]([Link]));
[Link]();
}

package lecturesOfJava;
import [Link];

public class Room {


String roomNo;
String roomType;
boolean acMachine;
double roomArea;
public void getData(String roomNo,String roomType,boolean
acMachine,double roomArea) {
[Link]=roomNo;
[Link]=roomType;
[Link]=roomArea;
[Link]=acMachine;
}
public void DisplayData() {
[Link]([Link]);
[Link]([Link]);
[Link]([Link]);
[Link]([Link]);
}

public static void main(String[] args) {


// TODO Auto-generated method stub
Scanner sc = new Scanner([Link]);
Room room1=new Room();

[Link]([Link](),[Link](),[Link](),sc.
nextDouble());
[Link]();
[Link]();

}
package lecturesOfJava;

class Shape {
void draw() {
[Link]("Drawing a shape");
}

void erase() {
[Link]("Erasing a shape");
}
}

class Circle extends Shape {


void draw() {
[Link]("Drawing a Circle");
}
void erase() {
[Link]("Erasing a Circle");
}
}

class Triangle extends Shape {


void draw() {
[Link]("Drawing a Triangle");
}
void erase() {
[Link]("Erasing a Triangle");
}
}

class Square extends Shape {


void draw() {
[Link]("Drawing a Square");
}
void erase() {
[Link]("Erasing a Square");
}
}

public class Example {


public static void main(String[] args) {
Shape[] shapes = {new Circle(), new Triangle(), new
Square()};

for (Shape shape : shapes) {


[Link]();
[Link]();
}
}
}

You might also like