What's new

Java Pa help

Joined
Jul 2, 2019
Posts
698
Reaction
1,190
ano po mali dito tinry kona e change ang #1 into Class Main error parin hehe patulong po

Screenshot_2022-05-19-15-28-15-80_a927ed2714ba3b9021f681846134c26f.jpg
 

Attachments

- Gray

Elite
Java:
class Student{
  String name;
// Overloading of constructor
public Student(){
  this.name="Unknown";
}
public Student(String sName){
  this.name=sName;
 }
 public static void main(String[]args){
    Student s1=new Student();
   Student s2=new Student("Aaron");
    System.out.println(" Name of Student s1:\n");
    System.out.println(" Name of Student s2:\n");
 }
}

Try mo TS not sure kung working pero wala nang error
 
Java:
class Student{
  String name;
// Overloading of constructor
public Student(){
  this.name="Unknown";
}
public Student(String sName){
  this.name=sName;
 }
 public static void main(String[]args){
    Student s1=new Student();
   Student s2=new Student("Aaron");
    System.out.println(" Name of Student s1:\n");
    System.out.println(" Name of Student s2:\n");
 }
}

Try mo TS not sure kung working pero wala nang error
ito parin error haha
+ javac -cp . Main.java
+ java -cp . Main
Error: Could not find or load main class Main

Caused by: java.lang.ClassNotFoundException: Main

kapag nag Class Main naman ako sa #1 ito naman error yung Student nanaman hahah

Screenshot_2022-05-19-18-16-28-00_a927ed2714ba3b9021f681846134c26f.jpg
 

Attachments

Main.java
Java:
class Main {
    public static void main(String[] args){
        Student s1 = new Student("Aaron");
        System.out.println("\nName of Student s1: " + s1.name);
    }
}

Student.java
Java:
public class Student {
    String name;
    public Student(String sName){
        this.name = sName;
    }
}

OUTPUT:
Name of Student s1: Aaron

Or just inside the Main.java

Java:
class Student {
    String name;
    public Student(String sName){
        this.name = sName;
    }
}

class Main {
    public static void main(String[] args){
        Student s1 = new Student("Aaron");
        System.out.println("\nName of Student s1: " + s1.name);
    }
}
 
Main.java
Java:
class Main {
    public static void main(String[] args){
        Student s1 = new Student("Aaron");
        System.out.println("\nName of Student s1: " + s1.name);
    }
}

Student.java
Java:
public class Student {
    String name;
    public Student(String sName){
        this.name = sName;
    }
}

OUTPUT:
Name of Student s1: Aaron

Or just inside the Main.java

Java:
class Student {
    String name;
    public Student(String sName){
        this.name = sName;
    }
}

class Main {
    public static void main(String[] args){
        Student s1 = new Student("Aaron");
        System.out.println("\nName of Student s1: " + s1.name);
    }
}
nice ty paps hehe
 
Top