Final Codes Wagera
Final Codes Wagera
class Circle{
public double radius;
class Rectangle{
public int length;
public int breadth;
class Test{
public static void main(String[] args) {
FinalClass obj = new FinalClass();
obj.finalMethod();
System.out.println("Value of final variable a: " + obj.a);
}
}
import java.util.Scanner;
}
}
public class CommandLine{
/* public static void main(String args[]) {
int i;
int sum = 0;
for (i = 0; i < args.length; i++) {
sum += Integer.parseInt(args[i]);
}
System.out.println("Sum of command line arguments: " + sum);
} */
import java.util.Scanner;
// This program checks if a given year is a leap year or not.
}
}
import java.util.Scanner;
if (str.equals(rev)) {
System.out.println(str + " is a palindrome.");
} else {
System.out.println(str + " is not a palindrome.");
}
}
}
class Bhaiya {
int age = 40;
Bhaiya() {
System.out.println("Bhaiya constructor called");
}
void about1() {
System.out.println("Papa hu main, pure duniya ka papa!");
}
}
Munna() {
super(); // Calls Bhaiya's constructor
System.out.println("Munna constructor called");
}
@Override
void about1() {
System.out.println("Bhaiya Bacahaooo!!");
super.about1(); // Call Bhaiya's about1()
System.out.println("Bhaiya's age is: " + super.age); // Access
Bhaiya's variable
System.out.println("Munna's age is: " + this.age); // Access
Munna's variable
}
}
class Test{
public static void main(String args[]){
MethodOverloading mo = new MethodOverloading();
System.out.println(mo.mul(5, 6)); // prints 30
System.out.println(mo.mul(10,10,10));
}
}
class Bhaiya {
public void about1(){
System.out.println("Papa hu main, pure duniya ka papa!");
}
}
class Test{
public static void main(String args[]){
}
}
public class ConstructorOverloading {
ConstructorOverloading() {
System.out.println("Default Constructor");
}
ConstructorOverloading(int a) {
System.out.println("Parameterized Constructor with int: " + a);
}
ConstructorOverloading(String s) {
System.out.println("Parameterized Constructor with String: " + s);
}
}
class Test{
public static void main(String[] args) {
ConstructorOverloading obj1 = new ConstructorOverloading();
ConstructorOverloading obj2 = new ConstructorOverloading(10);
ConstructorOverloading obj3 = new ConstructorOverloading("Spandan
Certified Java Programmer");
}
}
class Europe{
static String Club;
int shirt;
String country;
static {
Club = "Barcelona";
System.out.println("Static block of Europe class executed");
}
}
class Test{
public static void main(String args[]){
Europe e1 = new Europe();
e1.country="Brazil";
e1.shirt=11;
class Test{
public static void main(String[] args) {
Dog d = new Dog();
d.name="Tommy";
d.age=7;
d.makenoise();
System.out.println("Name:" + d.name + " " + "Age:" + d.age);
}
}
class Bhaiya {
public void about1(){
System.out.println("Papa hu main, pure duniya ka papa!");
}
}
class Test{
public static void main(String args[]){
Munna m = new Munna();
m.about1();
m.about2();
}
}
interface A{
void hola();
void bhola();
}
class B implements A{
class C extends B{
@Override
public void hola(){
System.out.println("Hola from C");
}
class Main{
public static void main(String[] args) {
C c = new C();
c.hola(); // Output: Hola from C
c.bhola(); // Output: bhola from B
}
}
class Main{
public static void main(String args[]){
Fan fan = new Fan();
TV tv = new TV();
fan.turnOn(); // Output: Fan is turned on.
tv.turnOn(); // Output: TV is turned on.
}
}
abstract class Employee{
abstract void calculateSalary(int hoursWorked, int hourlyRate);
}
class Main{
public static void main(String args[]) {
FullTimeEmployee emp = new FullTimeEmployee(40, 20);
emp.calculateSalary(emp.hoursWorked, emp.hourlyRate); // Output: Full-
time employee salary: 800
}
// Output: Credentials Acquired!
}
class Main{
public static void main(String args[]) {
FullTimeEmployee emp = new FullTimeEmployee(40, 20);
emp.calculateSalary(emp.hoursWorked, emp.hourlyRate); // Output: Full-
time employee salary: 800
}
// Output: Credentials Acquired!
}
class Box {
int value;
Box(int value) {
this.value = value;
}
Box doubleValue(Box b) {
return new Box(b.value * 2);
}
public static void main(String[] args) {
Box b1 = new Box(10);
Box b2 = b1.doubleValue(b1);
System.out.println("Doubled Value: " + b2.value);
}
}